Don't fly if not allowed and sharding command set
This commit is contained in:
parent
3e520e7e9f
commit
d3fc83386d
@ -38,6 +38,7 @@ import com.massivecraft.massivecore.command.type.RegistryType;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreChestGui;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreCollTick;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandRegistration;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreCommandSet;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreDatabase;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreDestination;
|
||||
import com.massivecraft.massivecore.engine.EngineMassiveCoreGank;
|
||||
@ -302,6 +303,7 @@ public class MassiveCore extends MassivePlugin
|
||||
EngineMassiveCoreChestGui.class,
|
||||
EngineMassiveCoreCollTick.class,
|
||||
EngineMassiveCoreCommandRegistration.class,
|
||||
EngineMassiveCoreCommandSet.class,
|
||||
EngineMassiveCoreDatabase.class,
|
||||
EngineMassiveCoreDestination.class,
|
||||
EngineMassiveCoreGank.class,
|
||||
|
@ -0,0 +1,84 @@
|
||||
package com.massivecraft.massivecore.command;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.command.type.sender.TypeSenderId;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCoreCommandSet;
|
||||
import com.massivecraft.massivecore.mixin.MixinEvent;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.PermissionUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class MassiveCommandSetSharding<T extends Serializable> extends MassiveCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Type<T> type;
|
||||
public Type<T> getType() { return this.type; }
|
||||
|
||||
private String permSetOther;
|
||||
public String getPermSetOther() { return permSetOther; }
|
||||
public void setPermSetOther(String permSetOther) { this.permSetOther = permSetOther; }
|
||||
public boolean hasPermSetOther() { return this.getPermSetOther() != null; }
|
||||
|
||||
private PlayerValue<T> playerValue;
|
||||
public PlayerValue<T> getPlayerValue() { return playerValue; }
|
||||
public void setPlayerValue(PlayerValue<T> playerValue) { this.playerValue = playerValue; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public MassiveCommandSetSharding(Type<T> type)
|
||||
{
|
||||
this(type, TypeSenderId.get());
|
||||
}
|
||||
|
||||
public MassiveCommandSetSharding(Type<T> type, Type<String> typeSenderId)
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
// Parameters
|
||||
this.addParameter(type);
|
||||
this.addParameter(typeSenderId, "player", "you");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// NAME
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getName()
|
||||
{
|
||||
List<String> aliases = this.getAliases();
|
||||
return aliases.get(aliases.size() - 1);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
T after = this.readArg();
|
||||
|
||||
String senderId = IdUtil.getId(sender);
|
||||
String targetId = this.readArg(senderId);
|
||||
boolean other = !targetId.equals(senderId);
|
||||
|
||||
// Check other
|
||||
if (other && this.hasPermSetOther())
|
||||
{
|
||||
if (!PermissionUtil.hasPermission(sender, this.getPermSetOther(), true)) return;
|
||||
}
|
||||
|
||||
EventMassiveCoreCommandSet event = new EventMassiveCoreCommandSet<T>(senderId, targetId, after, this.getPlayerValue(), this.getName());
|
||||
MixinEvent.get().distribute(event, true);
|
||||
}
|
||||
|
||||
}
|
12
src/com/massivecraft/massivecore/command/PlayerValue.java
Normal file
12
src/com/massivecraft/massivecore/command/PlayerValue.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.massivecraft.massivecore.command;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface PlayerValue<T extends Serializable> extends Serializable
|
||||
{
|
||||
T getValue(Player player) throws MassiveException;
|
||||
void setValue(T value, Player player) throws MassiveException;
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.massivecraft.massivecore.engine;
|
||||
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.PlayerValue;
|
||||
import com.massivecraft.massivecore.command.type.RegistryType;
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCoreCommandSet;
|
||||
import com.massivecraft.massivecore.mixin.MixinDisplayName;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class EngineMassiveCoreCommandSet extends Engine
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static EngineMassiveCoreCommandSet i = new EngineMassiveCoreCommandSet();
|
||||
public static EngineMassiveCoreCommandSet get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// RUN
|
||||
// -------------------------------------------- //
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public <T extends Serializable> void setValueListener(EventMassiveCoreCommandSet<T> event)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.setValue(event);
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
MixinMessage.get().messageOne(event.getSenderId(), e.getMessages());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public <T extends Serializable> void setValue(EventMassiveCoreCommandSet<T> event) throws MassiveException
|
||||
{
|
||||
String senderId = event.getSenderId();
|
||||
String targetId = event.getTargetId();
|
||||
T after = event.getValue();
|
||||
PlayerValue<T> playerValue = event.getPlayerValue();
|
||||
String name = event.getName();
|
||||
|
||||
Player player = IdUtil.getPlayer(targetId);
|
||||
if (player == null) return;
|
||||
|
||||
T before = playerValue.getValue(player);
|
||||
|
||||
Type<T> type = (Type<T>) RegistryType.getType(after.getClass());
|
||||
String afterDesc = type.getVisual(after);
|
||||
String targetDesc = this.getTargetDesc(targetId, senderId, name);
|
||||
|
||||
// NoChange
|
||||
if (after == before)
|
||||
{
|
||||
throw new MassiveException().addMsg("%s<i> is already <h>%s<i>.", targetDesc, afterDesc);
|
||||
}
|
||||
|
||||
// Apply
|
||||
playerValue.setValue(after, player);
|
||||
|
||||
// Inform
|
||||
MixinMessage.get().msgOne(senderId, "%s<i> is now <h>%s<i>.", targetDesc, afterDesc);
|
||||
|
||||
// Inform target
|
||||
if (!targetId.equals(senderId))
|
||||
{
|
||||
MixinMessage.get().msgOne(targetId, "%s<i> is now <h>%s<i>.", getTargetDesc(targetId, targetId, name), afterDesc);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTargetDesc(String targetId, String watcherId, String name)
|
||||
{
|
||||
if (targetId.equals(watcherId))
|
||||
{
|
||||
return Txt.parse("<i>Your <h>%s", name);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Txt.parse("<h>%s <i>of %s", Txt.upperCaseFirst(name), MixinDisplayName.get().getDisplayName(targetId, watcherId));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.massivecraft.massivecore.event;
|
||||
|
||||
import com.massivecraft.massivecore.command.PlayerValue;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class EventMassiveCoreCommandSet<T extends Serializable> extends EventMassiveCore implements Serializable
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REQUIRED EVENT CODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@Override public HandlerList getHandlers() { return handlers; }
|
||||
public static HandlerList getHandlerList() { return handlers; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String senderId;
|
||||
public String getSenderId() { return senderId; }
|
||||
|
||||
private final String targetId;
|
||||
public String getTargetId() { return targetId; }
|
||||
|
||||
private final T value;
|
||||
public T getValue() { return value; }
|
||||
|
||||
private final PlayerValue<T> playerValue;
|
||||
public PlayerValue<T> getPlayerValue() { return playerValue; }
|
||||
|
||||
private final String name;
|
||||
public String getName() { return name; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public EventMassiveCoreCommandSet(String senderId, String targetId, T value, PlayerValue<T> playerValue, String name)
|
||||
{
|
||||
this.senderId = senderId;
|
||||
this.targetId = targetId;
|
||||
this.value = value;
|
||||
this.playerValue = playerValue;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
@ -85,6 +85,11 @@ public class EventMassiveCorePlayerUpdate extends EventMassiveCore
|
||||
|
||||
EventMassiveCorePlayerUpdate event = new EventMassiveCorePlayerUpdate(player, current);
|
||||
event.run();
|
||||
|
||||
// If fly allowed is false, then fly active may not be true.
|
||||
// Because fly active uses current=true and everything else current=false
|
||||
// Then fly allowed might be reset when fly active doesn't get reset. That we do here.
|
||||
if (!event.isFlyAllowed()) event.setFlyActive(false);
|
||||
|
||||
setMaxHealth(player, event.getMaxHealth());
|
||||
setFlyAllowed(player, event.isFlyAllowed());
|
||||
|
Loading…
Reference in New Issue
Block a user