Improved the player update event system.
This commit is contained in:
parent
e2b3b668af
commit
6eb877d340
@ -44,6 +44,12 @@ import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreBuffer;
|
|||||||
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreCmdurl;
|
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreCmdurl;
|
||||||
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreStore;
|
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreStore;
|
||||||
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreUsys;
|
import com.massivecraft.massivecore.command.massivecore.CmdMassiveCoreUsys;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandRegistration;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreDestination;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreMain;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCorePlayerUpdate;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
|
||||||
import com.massivecraft.massivecore.integration.vault.IntegrationVault;
|
import com.massivecraft.massivecore.integration.vault.IntegrationVault;
|
||||||
import com.massivecraft.massivecore.mixin.EngineTeleportMixinCause;
|
import com.massivecraft.massivecore.mixin.EngineTeleportMixinCause;
|
||||||
import com.massivecraft.massivecore.mson.Mson;
|
import com.massivecraft.massivecore.mson.Mson;
|
||||||
@ -184,13 +190,14 @@ public class MassiveCore extends MassivePlugin
|
|||||||
|
|
||||||
// Engine
|
// Engine
|
||||||
EngineCollTick.get().activate();
|
EngineCollTick.get().activate();
|
||||||
MassiveCoreEngineMain.get().activate();
|
EngineMassiveCoreMain.get().activate();
|
||||||
MassiveCoreEngineVariable.get().activate();
|
EngineMassiveCoreVariable.get().activate();
|
||||||
EngineScheduledTeleport.get().activate();
|
EngineScheduledTeleport.get().activate();
|
||||||
EngineTeleportMixinCause.get().activate();
|
EngineTeleportMixinCause.get().activate();
|
||||||
MassiveCoreEngineWorldNameSet.get().activate();
|
EngineMassiveCoreWorldNameSet.get().activate();
|
||||||
MassiveCoreEngineCommandRegistration.get().activate();
|
EngineMassiveCoreCommandRegistration.get().activate();
|
||||||
MassiveCoreEngineDestination.get().activate();
|
EngineMassiveCoreDestination.get().activate();
|
||||||
|
EngineMassiveCorePlayerUpdate.get().activate();
|
||||||
PlayerUtil.get().activate();
|
PlayerUtil.get().activate();
|
||||||
EngineChestGui.get().activate();
|
EngineChestGui.get().activate();
|
||||||
EngineGank.get().activate();
|
EngineGank.get().activate();
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.massivecraft.massivecore.command.massivecore;
|
package com.massivecraft.massivecore.command.massivecore;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineVariable;
|
|
||||||
import com.massivecraft.massivecore.MassiveCorePerm;
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
|
|
||||||
public class CmdMassiveCoreBufferAdd extends MassiveCommand
|
public class CmdMassiveCoreBufferAdd extends MassiveCommand
|
||||||
{
|
{
|
||||||
@ -34,9 +34,9 @@ public class CmdMassiveCoreBufferAdd extends MassiveCommand
|
|||||||
{
|
{
|
||||||
String string = this.readArg();
|
String string = this.readArg();
|
||||||
|
|
||||||
String buffer = MassiveCoreEngineVariable.getBuffer(sender);
|
String buffer = EngineMassiveCoreVariable.getBuffer(sender);
|
||||||
buffer += string;
|
buffer += string;
|
||||||
MassiveCoreEngineVariable.setBuffer(sender, buffer);
|
EngineMassiveCoreVariable.setBuffer(sender, buffer);
|
||||||
|
|
||||||
msg("<i>Buffer Add");
|
msg("<i>Buffer Add");
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.massivecraft.massivecore.command.massivecore;
|
package com.massivecraft.massivecore.command.massivecore;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineVariable;
|
|
||||||
import com.massivecraft.massivecore.MassiveCorePerm;
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
|
|
||||||
public class CmdMassiveCoreBufferClear extends MassiveCommand
|
public class CmdMassiveCoreBufferClear extends MassiveCommand
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ public class CmdMassiveCoreBufferClear extends MassiveCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
MassiveCoreEngineVariable.setBuffer(sender, "");
|
EngineMassiveCoreVariable.setBuffer(sender, "");
|
||||||
|
|
||||||
msg("<i>Buffer Clear");
|
msg("<i>Buffer Clear");
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.massivecraft.massivecore.command.massivecore;
|
package com.massivecraft.massivecore.command.massivecore;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineVariable;
|
|
||||||
import com.massivecraft.massivecore.MassiveCorePerm;
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
|
|
||||||
public class CmdMassiveCoreBufferPrint extends MassiveCommand
|
public class CmdMassiveCoreBufferPrint extends MassiveCommand
|
||||||
{
|
{
|
||||||
@ -27,7 +27,7 @@ public class CmdMassiveCoreBufferPrint extends MassiveCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform()
|
public void perform()
|
||||||
{
|
{
|
||||||
String buffer = MassiveCoreEngineVariable.getBuffer(sender);
|
String buffer = EngineMassiveCoreVariable.getBuffer(sender);
|
||||||
if (buffer == null || buffer.length() == 0)
|
if (buffer == null || buffer.length() == 0)
|
||||||
{
|
{
|
||||||
msg("<i>Nothing to print. Your buffer is empty.");
|
msg("<i>Nothing to print. Your buffer is empty.");
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.massivecraft.massivecore.command.massivecore;
|
package com.massivecraft.massivecore.command.massivecore;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineVariable;
|
|
||||||
import com.massivecraft.massivecore.MassiveCorePerm;
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
|
|
||||||
public class CmdMassiveCoreBufferSet extends MassiveCommand
|
public class CmdMassiveCoreBufferSet extends MassiveCommand
|
||||||
{
|
{
|
||||||
@ -34,7 +34,7 @@ public class CmdMassiveCoreBufferSet extends MassiveCommand
|
|||||||
{
|
{
|
||||||
String string = this.readArg();
|
String string = this.readArg();
|
||||||
|
|
||||||
MassiveCoreEngineVariable.setBuffer(sender, string);
|
EngineMassiveCoreVariable.setBuffer(sender, string);
|
||||||
|
|
||||||
msg("<i>Buffer was Set");
|
msg("<i>Buffer was Set");
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.massivecraft.massivecore.command.massivecore;
|
package com.massivecraft.massivecore.command.massivecore;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineVariable;
|
|
||||||
import com.massivecraft.massivecore.MassiveCorePerm;
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreVariable;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public class CmdMassiveCoreBufferWhitespace extends MassiveCommand
|
public class CmdMassiveCoreBufferWhitespace extends MassiveCommand
|
||||||
@ -37,9 +37,9 @@ public class CmdMassiveCoreBufferWhitespace extends MassiveCommand
|
|||||||
|
|
||||||
String string = Txt.repeat(" ", times);
|
String string = Txt.repeat(" ", times);
|
||||||
|
|
||||||
String buffer = MassiveCoreEngineVariable.getBuffer(sender);
|
String buffer = EngineMassiveCoreVariable.getBuffer(sender);
|
||||||
buffer += string;
|
buffer += string;
|
||||||
MassiveCoreEngineVariable.setBuffer(sender, buffer);
|
EngineMassiveCoreVariable.setBuffer(sender, buffer);
|
||||||
|
|
||||||
msg("<i>Buffer Whitespace");
|
msg("<i>Buffer Whitespace");
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineCommandRegistration;
|
|
||||||
import com.massivecraft.massivecore.MassiveException;
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandRegistration;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
// We operate without the leading slash as much as possible.
|
// We operate without the leading slash as much as possible.
|
||||||
@ -111,8 +111,8 @@ public class TypeStringCommand extends TypeAbstract<String>
|
|||||||
|
|
||||||
public static Map<String, Command> getKnownCommands()
|
public static Map<String, Command> getKnownCommands()
|
||||||
{
|
{
|
||||||
SimpleCommandMap simpleCommandMap = MassiveCoreEngineCommandRegistration.getSimpleCommandMap();
|
SimpleCommandMap simpleCommandMap = EngineMassiveCoreCommandRegistration.getSimpleCommandMap();
|
||||||
Map<String, Command> knownCommands = MassiveCoreEngineCommandRegistration.getSimpleCommandMapDotKnownCommands(simpleCommandMap);
|
Map<String, Command> knownCommands = EngineMassiveCoreCommandRegistration.getSimpleCommandMapDotKnownCommands(simpleCommandMap);
|
||||||
return knownCommands;
|
return knownCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.massivecore;
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -12,18 +12,20 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||||
import com.massivecraft.massivecore.command.MassiveCoreBukkitCommand;
|
import com.massivecraft.massivecore.command.MassiveCoreBukkitCommand;
|
||||||
import com.massivecraft.massivecore.util.ReflectionUtil;
|
import com.massivecraft.massivecore.util.ReflectionUtil;
|
||||||
|
|
||||||
public class MassiveCoreEngineCommandRegistration extends EngineAbstract
|
public class EngineMassiveCoreCommandRegistration extends EngineAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MassiveCoreEngineCommandRegistration i = new MassiveCoreEngineCommandRegistration();
|
private static EngineMassiveCoreCommandRegistration i = new EngineMassiveCoreCommandRegistration();
|
||||||
public static MassiveCoreEngineCommandRegistration get() { return i; }
|
public static EngineMassiveCoreCommandRegistration get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.massivecore;
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,6 +11,9 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
import com.massivecraft.massivecore.MassiveException;
|
||||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
import com.massivecraft.massivecore.command.type.TypePS;
|
import com.massivecraft.massivecore.command.type.TypePS;
|
||||||
import com.massivecraft.massivecore.command.type.TypeWorldId;
|
import com.massivecraft.massivecore.command.type.TypeWorldId;
|
||||||
@ -28,14 +31,14 @@ import com.massivecraft.massivecore.teleport.DestinationUtil;
|
|||||||
import com.massivecraft.massivecore.teleport.DestinationWorld;
|
import com.massivecraft.massivecore.teleport.DestinationWorld;
|
||||||
import com.massivecraft.massivecore.util.IdUtil;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
|
|
||||||
public class MassiveCoreEngineDestination extends EngineAbstract
|
public class EngineMassiveCoreDestination extends EngineAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MassiveCoreEngineDestination i = new MassiveCoreEngineDestination();
|
private static EngineMassiveCoreDestination i = new EngineMassiveCoreDestination();
|
||||||
public static MassiveCoreEngineDestination get() { return i; }
|
public static EngineMassiveCoreDestination get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.massivecore;
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -27,6 +27,13 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
|||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||||
|
import com.massivecraft.massivecore.Predicate;
|
||||||
|
import com.massivecraft.massivecore.PredicateStartsWithIgnoreCase;
|
||||||
|
import com.massivecraft.massivecore.SenderPresence;
|
||||||
|
import com.massivecraft.massivecore.SenderType;
|
||||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
||||||
@ -43,14 +50,14 @@ import com.massivecraft.massivecore.util.MUtil;
|
|||||||
import com.massivecraft.massivecore.util.SmokeUtil;
|
import com.massivecraft.massivecore.util.SmokeUtil;
|
||||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||||
|
|
||||||
public class MassiveCoreEngineMain extends EngineAbstract
|
public class EngineMassiveCoreMain extends EngineAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MassiveCoreEngineMain i = new MassiveCoreEngineMain();
|
private static EngineMassiveCoreMain i = new EngineMassiveCoreMain();
|
||||||
public static MassiveCoreEngineMain get() { return i; }
|
public static EngineMassiveCoreMain get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
@ -0,0 +1,140 @@
|
|||||||
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
||||||
|
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
||||||
|
import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate;
|
||||||
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event triggers the EventMassiveCorePlayerUpdate on every block change.
|
||||||
|
* It also runs it in reset mode rather than update mode upon world change.
|
||||||
|
*/
|
||||||
|
public class EngineMassiveCorePlayerUpdate extends EngineAbstract
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static EngineMassiveCorePlayerUpdate i = new EngineMassiveCorePlayerUpdate();
|
||||||
|
public static EngineMassiveCorePlayerUpdate get() { return i; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return MassiveCore.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// UPDATE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static void update(Player player, boolean current)
|
||||||
|
{
|
||||||
|
// If this player is actually a player and not an NPC ...
|
||||||
|
if (MUtil.isntPlayer(player)) return;
|
||||||
|
|
||||||
|
// ... and the player is alive ...
|
||||||
|
if (player.isDead()) return;
|
||||||
|
|
||||||
|
// ... store data for no cheat plus bug fix ...
|
||||||
|
if (player.isFlying())
|
||||||
|
{
|
||||||
|
setLastFlyActive(player, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... then trigger an update.
|
||||||
|
EventMassiveCorePlayerUpdate.run(player, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// We reset to default values as early as we can on join.
|
||||||
|
// This is for the sake of security.
|
||||||
|
// Old insane values left in the player dat files will be reset.
|
||||||
|
// If they were wanted they will have to be redeclared by the responsible plugin again.
|
||||||
|
// NOTE: Can't be cancelled
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void update(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
update(event.getPlayer(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void update(EventMassiveCoreAfterPlayerTeleport event)
|
||||||
|
{
|
||||||
|
update(event.getPlayer(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void update(EventMassiveCoreAfterPlayerRespawn event)
|
||||||
|
{
|
||||||
|
update(event.getPlayer(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void update(PlayerChangedWorldEvent event)
|
||||||
|
{
|
||||||
|
update(event.getPlayer(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void update(PlayerMoveEvent event)
|
||||||
|
{
|
||||||
|
// Only on block change!
|
||||||
|
if (MUtil.isSameBlock(event)) return;
|
||||||
|
|
||||||
|
update(event.getPlayer(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FIX NO CHEAT PLUS BUG
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static Map<UUID, Long> idToLastFlyActive = new HashMap<UUID, Long>();
|
||||||
|
public static Long getLastFlyActive(Player player)
|
||||||
|
{
|
||||||
|
return idToLastFlyActive.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
public static void setLastFlyActive(Player player, Long millis)
|
||||||
|
{
|
||||||
|
idToLastFlyActive.put(player.getUniqueId(), millis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||||
|
public void fixNoCheatPlusBug(EntityDamageEvent event)
|
||||||
|
{
|
||||||
|
// If a player ...
|
||||||
|
if (MUtil.isntPlayer(event.getEntity())) return;
|
||||||
|
Player player = (Player)event.getEntity();
|
||||||
|
|
||||||
|
// ... is taking fall damage ...
|
||||||
|
if (event.getCause() != DamageCause.FALL) return;
|
||||||
|
|
||||||
|
// ... within 2 seconds of flying ...
|
||||||
|
Long lastActive = getLastFlyActive(player);
|
||||||
|
if (lastActive == null) return;
|
||||||
|
if (System.currentTimeMillis() - lastActive > 2000) return;
|
||||||
|
|
||||||
|
// ... cancel the event.
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.massivecore;
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,18 +17,22 @@ import org.bukkit.inventory.meta.BookMeta;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||||
|
import com.massivecraft.massivecore.MassiveCorePerm;
|
||||||
import com.massivecraft.massivecore.util.IdUtil;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
import com.massivecraft.massivecore.util.Txt;
|
import com.massivecraft.massivecore.util.Txt;
|
||||||
|
|
||||||
public class MassiveCoreEngineVariable extends EngineAbstract
|
public class EngineMassiveCoreVariable extends EngineAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MassiveCoreEngineVariable i = new MassiveCoreEngineVariable();
|
private static EngineMassiveCoreVariable i = new EngineMassiveCoreVariable();
|
||||||
public static MassiveCoreEngineVariable get() { return i; }
|
public static EngineMassiveCoreVariable get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
@ -1,4 +1,4 @@
|
|||||||
package com.massivecraft.massivecore;
|
package com.massivecraft.massivecore.engine;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -12,14 +12,17 @@ import org.bukkit.event.world.WorldLoadEvent;
|
|||||||
import org.bukkit.event.world.WorldUnloadEvent;
|
import org.bukkit.event.world.WorldUnloadEvent;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class MassiveCoreEngineWorldNameSet extends EngineAbstract
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
|
|
||||||
|
public class EngineMassiveCoreWorldNameSet extends EngineAbstract
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// INSTANCE & CONSTRUCT
|
// INSTANCE & CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
|
||||||
private static MassiveCoreEngineWorldNameSet i = new MassiveCoreEngineWorldNameSet();
|
private static EngineMassiveCoreWorldNameSet i = new EngineMassiveCoreWorldNameSet();
|
||||||
public static MassiveCoreEngineWorldNameSet get() { return i; }
|
public static EngineMassiveCoreWorldNameSet get() { return i; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// OVERRIDE
|
// OVERRIDE
|
@ -1,10 +1,26 @@
|
|||||||
package com.massivecraft.massivecore.event;
|
package com.massivecraft.massivecore.event;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Damageable;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import com.massivecraft.massivecore.util.PlayerUtil;
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The purpose of this event is to allow multiple plugins to have a say about these player properties.
|
||||||
|
*
|
||||||
|
* It would have been great if the properties were event driven themselves.
|
||||||
|
* Meaning Bukkit could run an event to calculate the value every time it was asked for.
|
||||||
|
* That is however not the case.
|
||||||
|
*
|
||||||
|
* So instead I trigger this event every once.
|
||||||
|
* This is done from EngineMassiveCorePlayerUpdate.
|
||||||
|
*
|
||||||
|
* The plugins wanting to have a say about the values can just listen to this event at the priority they want and modify values they care for.
|
||||||
|
*/
|
||||||
public class EventMassiveCorePlayerUpdate extends EventMassiveCore
|
public class EventMassiveCorePlayerUpdate extends EventMassiveCore
|
||||||
{
|
{
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -38,17 +54,231 @@ public class EventMassiveCorePlayerUpdate extends EventMassiveCore
|
|||||||
public float getFlySpeed() { return this.flySpeed; }
|
public float getFlySpeed() { return this.flySpeed; }
|
||||||
public void setFlySpeed(float flySpeed) { this.flySpeed = flySpeed; }
|
public void setFlySpeed(float flySpeed) { this.flySpeed = flySpeed; }
|
||||||
|
|
||||||
|
private float walkSpeed;
|
||||||
|
public float getWalkSpeed() { return this.walkSpeed; }
|
||||||
|
public void setWalkSpeed(float walkSpeed) { this.walkSpeed = walkSpeed; }
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
// The boolean current decides if we use the current values or the default ones.
|
||||||
|
// With current true it will be an "update".
|
||||||
|
// With current false it will be a "reset".
|
||||||
|
|
||||||
public EventMassiveCorePlayerUpdate(Player player)
|
public EventMassiveCorePlayerUpdate(Player player, boolean current)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.maxHealth = PlayerUtil.getMaxHealth(player);
|
|
||||||
this.flyAllowed = PlayerUtil.isFlyAllowed(player);
|
this.maxHealth = getMaxHealth(player, current);
|
||||||
this.flyActive = PlayerUtil.isFlyActive(player);
|
this.flyAllowed = isFlyAllowed(player, current);
|
||||||
this.flySpeed = PlayerUtil.getFlySpeed(player);
|
this.flyActive = isFlyActive(player, current);
|
||||||
|
this.flySpeed = getFlySpeed(player, current);
|
||||||
|
this.walkSpeed = getWalkSpeed(player, current);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// RUN
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static void run(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if (MUtil.isntPlayer(player)) return;
|
||||||
|
|
||||||
|
EventMassiveCorePlayerUpdate event = new EventMassiveCorePlayerUpdate(player, current);
|
||||||
|
event.run();
|
||||||
|
|
||||||
|
setMaxHealth(player, event.getMaxHealth());
|
||||||
|
setFlyAllowed(player, event.isFlyAllowed());
|
||||||
|
setFlyActive(player, event.isFlyActive());
|
||||||
|
setFlySpeed(player, event.getFlySpeed());
|
||||||
|
setWalkSpeed(player, event.getWalkSpeed());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void run(Player player)
|
||||||
|
{
|
||||||
|
run(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// MAX HEALTH
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static boolean setMaxHealth(Player player, double maxHealth)
|
||||||
|
{
|
||||||
|
// NoChange
|
||||||
|
if (getMaxHealth(player) == maxHealth) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
player.setMaxHealth(maxHealth);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getMaxHealth(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if ( ! current) return 20D;
|
||||||
|
|
||||||
|
Damageable d = (Damageable) player;
|
||||||
|
return d.getMaxHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double getMaxHealth(Player player)
|
||||||
|
{
|
||||||
|
return getMaxHealth(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean resetMaxHealth(Player player)
|
||||||
|
{
|
||||||
|
return setMaxHealth(player, getMaxHealth(player, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FLY ALLOWED
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
// For backwards version compatibility we use the enumeration names rather than the enumerations themselves.
|
||||||
|
public static Set<String> FLY_DEFAULT_GAME_MODE_NAMES = new MassiveSet<String>(
|
||||||
|
"CREATIVE",
|
||||||
|
"SPECTATOR"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static boolean setFlyAllowed(Player player, boolean allowed)
|
||||||
|
{
|
||||||
|
// NoChange
|
||||||
|
if (isFlyAllowed(player) == allowed) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
player.setFallDistance(0);
|
||||||
|
player.setAllowFlight(allowed);
|
||||||
|
player.setFallDistance(0);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFlyAllowed(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if ( ! current) return FLY_DEFAULT_GAME_MODE_NAMES.contains(player.getGameMode().name());
|
||||||
|
|
||||||
|
return player.getAllowFlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFlyAllowed(Player player)
|
||||||
|
{
|
||||||
|
return isFlyAllowed(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean resetFlyAllowed(Player player)
|
||||||
|
{
|
||||||
|
return setFlyAllowed(player, isFlyAllowed(player, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FLY ACTIVE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public static boolean setFlyActive(Player player, boolean active)
|
||||||
|
{
|
||||||
|
// NoChange
|
||||||
|
if (isFlyActive(player) == active) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
player.setFallDistance(0);
|
||||||
|
player.setFlying(active);
|
||||||
|
player.setFallDistance(0);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFlyActive(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if ( ! current) return FLY_DEFAULT_GAME_MODE_NAMES.contains(player.getGameMode().name());
|
||||||
|
|
||||||
|
return player.isFlying();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFlyActive(Player player)
|
||||||
|
{
|
||||||
|
return isFlyActive(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean resetFlyActive(Player player)
|
||||||
|
{
|
||||||
|
return setFlyActive(player, isFlyActive(player, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// FLY SPEED
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public final static float DEFAULT_FLY_SPEED = 0.1f;
|
||||||
|
|
||||||
|
public static boolean setFlySpeed(Player player, float speed)
|
||||||
|
{
|
||||||
|
// NoChange
|
||||||
|
if (getFlySpeed(player) == speed) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
player.setFallDistance(0);
|
||||||
|
player.setFlySpeed(speed);
|
||||||
|
player.setFallDistance(0);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getFlySpeed(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if ( ! current) return DEFAULT_FLY_SPEED;
|
||||||
|
|
||||||
|
return player.getFlySpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getFlySpeed(Player player)
|
||||||
|
{
|
||||||
|
return getFlySpeed(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean resetFlySpeed(Player player)
|
||||||
|
{
|
||||||
|
return setFlySpeed(player, getFlySpeed(player, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// WALK SPEED
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
public final static float DEFAULT_WALK_SPEED = 0.2f;
|
||||||
|
|
||||||
|
public static boolean setWalkSpeed(Player player, float speed)
|
||||||
|
{
|
||||||
|
// NoChange
|
||||||
|
if (getWalkSpeed(player) == speed) return false;
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
player.setWalkSpeed(speed);
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getWalkSpeed(Player player, boolean current)
|
||||||
|
{
|
||||||
|
if ( ! current) return DEFAULT_WALK_SPEED;
|
||||||
|
|
||||||
|
return player.getWalkSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getWalkSpeed(Player player)
|
||||||
|
{
|
||||||
|
return getWalkSpeed(player, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean resetWalkSpeed(Player player)
|
||||||
|
{
|
||||||
|
return setWalkSpeed(player, getWalkSpeed(player, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,12 @@ import org.bukkit.projectiles.ProjectileSource;
|
|||||||
|
|
||||||
import com.massivecraft.massivecore.CaseInsensitiveComparator;
|
import com.massivecraft.massivecore.CaseInsensitiveComparator;
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineMain;
|
|
||||||
import com.massivecraft.massivecore.MassiveCoreEngineWorldNameSet;
|
|
||||||
import com.massivecraft.massivecore.Predicate;
|
import com.massivecraft.massivecore.Predicate;
|
||||||
import com.massivecraft.massivecore.collections.MassiveList;
|
import com.massivecraft.massivecore.collections.MassiveList;
|
||||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||||
import com.massivecraft.massivecore.collections.MassiveTreeSet;
|
import com.massivecraft.massivecore.collections.MassiveTreeSet;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreMain;
|
||||||
|
import com.massivecraft.massivecore.engine.EngineMassiveCoreWorldNameSet;
|
||||||
import com.massivecraft.massivecore.util.extractor.Extractor;
|
import com.massivecraft.massivecore.util.extractor.Extractor;
|
||||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayer;
|
import com.massivecraft.massivecore.util.extractor.ExtractorPlayer;
|
||||||
import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
|
import com.massivecraft.massivecore.util.extractor.ExtractorPlayerName;
|
||||||
@ -224,7 +224,7 @@ public class MUtil
|
|||||||
if (address != null) return getIp(address);
|
if (address != null) return getIp(address);
|
||||||
|
|
||||||
String id = IdUtil.getId(player);
|
String id = IdUtil.getId(player);
|
||||||
PlayerLoginEvent event = MassiveCoreEngineMain.idToPlayerLoginEvent.get(id);
|
PlayerLoginEvent event = EngineMassiveCoreMain.idToPlayerLoginEvent.get(id);
|
||||||
if (event != null) return getIp(event);
|
if (event != null) return getIp(event);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -1178,7 +1178,7 @@ public class MUtil
|
|||||||
if (MUtil.isntPlayer(player)) return null;
|
if (MUtil.isntPlayer(player)) return null;
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
return MassiveCoreEngineMain.kickedPlayerReasons.get(uuid);
|
return EngineMassiveCoreMain.kickedPlayerReasons.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean causedByKick(PlayerQuitEvent event)
|
public static boolean causedByKick(PlayerQuitEvent event)
|
||||||
@ -1282,7 +1282,7 @@ public class MUtil
|
|||||||
|
|
||||||
public static Set<String> getLoadedWorldNames()
|
public static Set<String> getLoadedWorldNames()
|
||||||
{
|
{
|
||||||
return MassiveCoreEngineWorldNameSet.get().getWorldNames();
|
return EngineMassiveCoreWorldNameSet.get().getWorldNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -7,8 +7,6 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
import java.util.concurrent.ConcurrentSkipListSet;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.entity.Damageable;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -16,7 +14,6 @@ import org.bukkit.event.EventPriority;
|
|||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
||||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||||
import org.bukkit.event.player.PlayerAnimationType;
|
import org.bukkit.event.player.PlayerAnimationType;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
@ -28,9 +25,6 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import com.massivecraft.massivecore.EngineAbstract;
|
import com.massivecraft.massivecore.EngineAbstract;
|
||||||
import com.massivecraft.massivecore.MassiveCore;
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerUpdate;
|
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
|
|
||||||
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
|
|
||||||
|
|
||||||
public class PlayerUtil extends EngineAbstract
|
public class PlayerUtil extends EngineAbstract
|
||||||
{
|
{
|
||||||
@ -362,255 +356,4 @@ public class PlayerUtil extends EngineAbstract
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// SETTINGS BY EVENT
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static void update(Player player)
|
|
||||||
{
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
EventMassiveCorePlayerUpdate event = new EventMassiveCorePlayerUpdate(player);
|
|
||||||
event.run();
|
|
||||||
|
|
||||||
setMaxHealth(player, event.getMaxHealth());
|
|
||||||
setFlyAllowed(player, event.isFlyAllowed());
|
|
||||||
setFlyActive(player, event.isFlyActive());
|
|
||||||
setFlySpeed(player, event.getFlySpeed());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void reset(Player player)
|
|
||||||
{
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
setMaxHealth(player, getMaxHealthDefault(player));
|
|
||||||
setFlyAllowed(player, isFlyAllowedDefault(player));
|
|
||||||
setFlyActive(player, isFlyActiveDefault(player));
|
|
||||||
setFlySpeed(player, getFlySpeedDefault(player));
|
|
||||||
|
|
||||||
update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Can't be cancelled
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void reset(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
// If we have a player ...
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
// ... and the player is alive ...
|
|
||||||
if (player.isDead()) return;
|
|
||||||
|
|
||||||
// ... trigger.
|
|
||||||
reset(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void update(EventMassiveCoreAfterPlayerTeleport event)
|
|
||||||
{
|
|
||||||
// If we have a player ...
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
// ... and the player is alive ...
|
|
||||||
if (player.isDead()) return;
|
|
||||||
|
|
||||||
// ... trigger.
|
|
||||||
update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void update(EventMassiveCoreAfterPlayerRespawn event)
|
|
||||||
{
|
|
||||||
// If we have a player ...
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
// ... and the player is alive ...
|
|
||||||
if (player.isDead()) return;
|
|
||||||
|
|
||||||
// ... trigger.
|
|
||||||
update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void update(PlayerChangedWorldEvent event)
|
|
||||||
{
|
|
||||||
// If we have a player ...
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
// ... and the player is alive ...
|
|
||||||
if (player.isDead()) return;
|
|
||||||
|
|
||||||
// ... trigger.
|
|
||||||
update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
|
||||||
public void update(PlayerMoveEvent event)
|
|
||||||
{
|
|
||||||
// If we have a player ...
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (MUtil.isntPlayer(player)) return;
|
|
||||||
|
|
||||||
// ... and the player is alive ...
|
|
||||||
if (player.isDead()) return;
|
|
||||||
|
|
||||||
// ... and the player moved from one block to another ...
|
|
||||||
if (event.getFrom().getBlock().equals(event.getTo().getBlock())) return;
|
|
||||||
|
|
||||||
// ... trigger.
|
|
||||||
update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// MAX HEALTH
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static boolean setMaxHealth(Player player, double maxHealth)
|
|
||||||
{
|
|
||||||
// NoChange
|
|
||||||
if (getMaxHealth(player) == maxHealth) return false;
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
player.setMaxHealth(maxHealth);
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getMaxHealth(Player player)
|
|
||||||
{
|
|
||||||
Damageable d = (Damageable) player;
|
|
||||||
return d.getMaxHealth();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double getMaxHealthDefault(Player player)
|
|
||||||
{
|
|
||||||
return 20D;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FLY: ALLOWED
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static boolean setFlyAllowed(Player player, boolean allowed)
|
|
||||||
{
|
|
||||||
// NoChange
|
|
||||||
if (isFlyAllowed(player) == allowed) return false;
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
player.setFallDistance(0);
|
|
||||||
player.setAllowFlight(allowed);
|
|
||||||
player.setFallDistance(0);
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFlyAllowed(Player player)
|
|
||||||
{
|
|
||||||
return player.getAllowFlight();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFlyAllowedDefault(Player player)
|
|
||||||
{
|
|
||||||
return player.getGameMode() == GameMode.CREATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FLY: ACTIVE
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public static Map<UUID, Long> idToLastFlyActive = new HashMap<UUID, Long>();
|
|
||||||
public static Long getLastFlyActive(Player player)
|
|
||||||
{
|
|
||||||
return idToLastFlyActive.get(player.getUniqueId());
|
|
||||||
}
|
|
||||||
public static void setLastFlyActive(Player player, Long millis)
|
|
||||||
{
|
|
||||||
idToLastFlyActive.put(player.getUniqueId(), millis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void negateNoCheatPlusBug(EntityDamageEvent event)
|
|
||||||
{
|
|
||||||
// If a player ...
|
|
||||||
if ( ! (event.getEntity() instanceof Player)) return;
|
|
||||||
Player player = (Player)event.getEntity();
|
|
||||||
|
|
||||||
// ... is taking fall damage ...
|
|
||||||
if (event.getCause() != DamageCause.FALL) return;
|
|
||||||
|
|
||||||
// ... within 2 seconds of flying ...
|
|
||||||
Long lastActive = getLastFlyActive(player);
|
|
||||||
if (lastActive == null) return;
|
|
||||||
if (System.currentTimeMillis() - lastActive > 2000) return;
|
|
||||||
|
|
||||||
// ... cancel the event.
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean setFlyActive(Player player, boolean active)
|
|
||||||
{
|
|
||||||
// Last Active Update
|
|
||||||
if (active)
|
|
||||||
{
|
|
||||||
setLastFlyActive(player, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
// NoChange
|
|
||||||
if (isFlyActive(player) == active) return false;
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
player.setFallDistance(0);
|
|
||||||
player.setFlying(active);
|
|
||||||
player.setFallDistance(0);
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFlyActive(Player player)
|
|
||||||
{
|
|
||||||
return player.isFlying();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isFlyActiveDefault(Player player)
|
|
||||||
{
|
|
||||||
return player.getGameMode() == GameMode.CREATIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------- //
|
|
||||||
// FLY: SPEED
|
|
||||||
// -------------------------------------------- //
|
|
||||||
|
|
||||||
public final static float DEFAULT_FLY_SPEED = 0.1f;
|
|
||||||
|
|
||||||
public static boolean setFlySpeed(Player player, float speed)
|
|
||||||
{
|
|
||||||
// NoChange
|
|
||||||
if (getFlySpeed(player) == speed) return false;
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
player.setFallDistance(0);
|
|
||||||
player.setFlySpeed(speed);
|
|
||||||
player.setFallDistance(0);
|
|
||||||
|
|
||||||
// Return
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getFlySpeed(Player player)
|
|
||||||
{
|
|
||||||
return player.getFlySpeed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getFlySpeedDefault(Player player)
|
|
||||||
{
|
|
||||||
return DEFAULT_FLY_SPEED;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user