mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-30 04:29:05 +00:00
Total rotation support
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.Command;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIris extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -5,10 +5,10 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.generator.IrisChunkGenerator;
|
||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
public class CommandIrisGoto extends MortarCommand
|
||||
|
||||
@@ -6,10 +6,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisMetrics;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.generator.IrisChunkGenerator;
|
||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisMetrics extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.Command;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObject extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -5,11 +5,11 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.Cuboid;
|
||||
import com.volmit.iris.util.Direction;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectContract extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -5,11 +5,11 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.Cuboid;
|
||||
import com.volmit.iris.util.Direction;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectExpand extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectP1 extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectP2 extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -11,10 +11,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.object.IrisObject;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectPaste extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -8,10 +8,10 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.object.IrisObject;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectSave extends MortarCommand
|
||||
{
|
||||
@@ -38,14 +38,14 @@ public class CommandIrisObjectSave extends MortarCommand
|
||||
|
||||
try
|
||||
{
|
||||
o.write(new File(Iris.instance.getDataFolder(), "objects/" + args[1] + ".iob"));
|
||||
sender.sendMessage("Saved " + "objects/" + args[1] + ".iob");
|
||||
o.write(new File(Iris.instance.getDataFolder(), "objects/" + args[0] + ".iob"));
|
||||
sender.sendMessage("Saved " + "objects/" + args[0] + ".iob");
|
||||
p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
||||
}
|
||||
|
||||
catch(IOException e)
|
||||
{
|
||||
sender.sendMessage("Failed to save " + "objects/" + args[1] + ".iob. Are you holding your wand?");
|
||||
sender.sendMessage("Failed to save " + "objects/" + args[0] + ".iob. Are you holding your wand?");
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.Cuboid;
|
||||
import com.volmit.iris.util.Direction;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectShift extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.volmit.iris.command;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisObjectWand extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -7,11 +7,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.Cuboid;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
import com.volmit.iris.util.Cuboid.CuboidDirection;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
|
||||
public class CommandIrisObjectXAY extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -7,11 +7,11 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.WandController;
|
||||
import com.volmit.iris.util.Cuboid;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
import com.volmit.iris.util.Cuboid.CuboidDirection;
|
||||
import com.volmit.iris.wand.WandController;
|
||||
|
||||
public class CommandIrisObjectXPY extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.Command;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisStudio extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisStudioClose extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.io.IOException;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.object.InterpolationMethod;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisBiomeGeneratorLink;
|
||||
@@ -17,6 +15,8 @@ import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.IO;
|
||||
import com.volmit.iris.util.JSONException;
|
||||
import com.volmit.iris.util.JSONObject;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@@ -43,6 +43,12 @@ public class CommandIrisStudioCreate extends MortarCommand
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.setLoadKey(args[0]);
|
||||
dimension.setName(Form.capitalizeWords(args[0].replaceAll("\\Q-\\E", " ")));
|
||||
|
||||
if(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "dimensions", dimension.getLoadKey() + ".json").exists())
|
||||
{
|
||||
sender.sendMessage("Project Already Exists! Open it instead!");
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage("Creating New Project \"" + dimension.getName() + "\"...");
|
||||
IrisRegion exampleRegion = new IrisRegion();
|
||||
exampleRegion.setName("Example Region");
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.volmit.iris.command;
|
||||
import java.io.File;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisStudioList extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisStudioOpen extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -7,8 +7,6 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.object.IrisGenerator;
|
||||
@@ -20,6 +18,8 @@ import com.volmit.iris.util.JSONObject;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.KSet;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisStudioPackage extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -6,11 +6,11 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.IrisMetrics;
|
||||
import com.volmit.iris.command.util.Command;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.generator.IrisChunkGenerator;
|
||||
import com.volmit.iris.gen.IrisChunkGenerator;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.Form;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisWhat extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisWhatBlock extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisWhatHand extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.command.util.Command;
|
||||
import com.volmit.iris.command.util.MortarCommand;
|
||||
import com.volmit.iris.command.util.MortarSender;
|
||||
import com.volmit.iris.util.Command;
|
||||
import com.volmit.iris.util.MortarCommand;
|
||||
import com.volmit.iris.util.MortarSender;
|
||||
|
||||
public class CommandIrisWorld extends MortarCommand
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.command.util.MortarPermission;
|
||||
import com.volmit.iris.command.util.Permission;
|
||||
import com.volmit.iris.util.MortarPermission;
|
||||
import com.volmit.iris.util.Permission;
|
||||
|
||||
public class PermissionIris extends MortarPermission
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.volmit.iris.command;
|
||||
|
||||
import com.volmit.iris.command.util.MortarPermission;
|
||||
import com.volmit.iris.util.MortarPermission;
|
||||
|
||||
public class PermissionIrisStudio extends MortarPermission
|
||||
{
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Command
|
||||
{
|
||||
String value() default "";
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Control
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
|
||||
public abstract class Controller implements IController
|
||||
{
|
||||
private int tickRate;
|
||||
private String name;
|
||||
|
||||
public Controller()
|
||||
{
|
||||
name = getClass().getSimpleName().replaceAll("Controller", "") + " Controller";
|
||||
tickRate = -1;
|
||||
}
|
||||
|
||||
protected void setTickRate(int rate)
|
||||
{
|
||||
this.tickRate = rate;
|
||||
}
|
||||
|
||||
protected void disableTicking()
|
||||
{
|
||||
setTickRate(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void l(Object l)
|
||||
{
|
||||
Iris.info("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void w(Object l)
|
||||
{
|
||||
Iris.warn("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void f(Object l)
|
||||
{
|
||||
Iris.error("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void v(Object l)
|
||||
{
|
||||
Iris.verbose("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void start();
|
||||
|
||||
@Override
|
||||
public abstract void stop();
|
||||
|
||||
@Override
|
||||
public abstract void tick();
|
||||
|
||||
@Override
|
||||
public int getTickInterval()
|
||||
{
|
||||
return tickRate;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
/**
|
||||
* Represents a pawn command
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public interface ICommand
|
||||
{
|
||||
public KList<String> getRequiredPermissions();
|
||||
|
||||
/**
|
||||
* Get the name of this command (node)
|
||||
*
|
||||
* @return the node
|
||||
*/
|
||||
public String getNode();
|
||||
|
||||
/**
|
||||
* Get all (realized) nodes of this command
|
||||
*
|
||||
* @return the nodes
|
||||
*/
|
||||
public KList<String> getNodes();
|
||||
|
||||
/**
|
||||
* Get all (every) node in this command
|
||||
*
|
||||
* @return all nodes
|
||||
*/
|
||||
public KList<String> getAllNodes();
|
||||
|
||||
/**
|
||||
* Add a node to this command
|
||||
*
|
||||
* @param node
|
||||
* the node
|
||||
*/
|
||||
public void addNode(String node);
|
||||
|
||||
/**
|
||||
* Handle a command. If this is a subcommand, parameters after the subcommand
|
||||
* will be adapted in args for you
|
||||
*
|
||||
* @param sender
|
||||
* the volume sender (pre-tagged)
|
||||
* @param args
|
||||
* the arguments after this command node
|
||||
* @return return true to mark it as handled
|
||||
*/
|
||||
public boolean handle(MortarSender sender, String[] args);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public interface IController extends Listener
|
||||
{
|
||||
public String getName();
|
||||
|
||||
public void start();
|
||||
|
||||
public void stop();
|
||||
|
||||
public void tick();
|
||||
|
||||
public int getTickInterval();
|
||||
|
||||
public void l(Object l);
|
||||
|
||||
public void w(Object l);
|
||||
|
||||
public void f(Object l);
|
||||
|
||||
public void v(Object l);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Instance
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
/**
|
||||
* Represents a pawn command
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public abstract class MortarCommand implements ICommand
|
||||
{
|
||||
private KList<MortarCommand> children;
|
||||
private KList<String> nodes;
|
||||
private KList<String> requiredPermissions;
|
||||
private String node;
|
||||
private String category;
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Override this with a super constructor as most commands shouldnt change these
|
||||
* parameters
|
||||
*
|
||||
* @param node
|
||||
* the node (primary node) i.e. volume
|
||||
* @param nodes
|
||||
* the aliases. i.e. v, vol, bile
|
||||
*/
|
||||
public MortarCommand(String node, String... nodes)
|
||||
{
|
||||
category = "";
|
||||
this.node = node;
|
||||
this.nodes = new KList<String>(nodes);
|
||||
requiredPermissions = new KList<>();
|
||||
children = buildChildren();
|
||||
description = "No Description";
|
||||
}
|
||||
|
||||
public void printHelp(MortarSender sender)
|
||||
{
|
||||
boolean b = false;
|
||||
|
||||
for(MortarCommand i : getChildren())
|
||||
{
|
||||
for(String j : i.getRequiredPermissions())
|
||||
{
|
||||
if(!sender.hasPermission(j))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
b = true;
|
||||
sender.sendMessage(ChatColor.GREEN + i.getNode() + " " + ChatColor.WHITE + i.getArgsUsage() + ChatColor.GRAY + " - " + i.getDescription());
|
||||
}
|
||||
|
||||
if(!b)
|
||||
{
|
||||
sender.sendMessage("There are either no sub-commands or you do not have permission to use them.");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getArgsUsage();
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
protected void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
protected void requiresPermission(MortarPermission node)
|
||||
{
|
||||
if(node == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
requiresPermission(node.toString());
|
||||
}
|
||||
|
||||
protected void requiresPermission(String node)
|
||||
{
|
||||
if(node == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
requiredPermissions.add(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getNodes()
|
||||
{
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getAllNodes()
|
||||
{
|
||||
return getNodes().copy().qadd(getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(String node)
|
||||
{
|
||||
getNodes().add(node);
|
||||
}
|
||||
|
||||
public KList<MortarCommand> getChildren()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
|
||||
private KList<MortarCommand> buildChildren()
|
||||
{
|
||||
KList<MortarCommand> p = new KList<>();
|
||||
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Command.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
MortarCommand pc = (MortarCommand) i.getType().getConstructor().newInstance();
|
||||
Command c = i.getAnnotation(Command.class);
|
||||
|
||||
if(!c.value().trim().isEmpty())
|
||||
{
|
||||
pc.setCategory(c.value().trim());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
pc.setCategory(getCategory());
|
||||
}
|
||||
|
||||
p.add(pc);
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getRequiredPermissions()
|
||||
{
|
||||
return requiredPermissions;
|
||||
}
|
||||
|
||||
public String getCategory()
|
||||
{
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category)
|
||||
{
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.volmit.iris.util.KList;
|
||||
|
||||
public abstract class MortarPermission
|
||||
{
|
||||
private MortarPermission parent;
|
||||
|
||||
public MortarPermission()
|
||||
{
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Permission.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
MortarPermission px = (MortarPermission) i.getType().getConstructor().newInstance();
|
||||
px.setParent(this);
|
||||
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, px);
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public KList<MortarPermission> getChildren()
|
||||
{
|
||||
KList<MortarPermission> p = new KList<>();
|
||||
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Permission.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
p.add((MortarPermission) i.get(Modifier.isStatic(i.getModifiers()) ? null : this));
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public String getFullNode()
|
||||
{
|
||||
if(hasParent())
|
||||
{
|
||||
return getParent().getFullNode() + "." + getNode();
|
||||
}
|
||||
|
||||
return getNode();
|
||||
}
|
||||
|
||||
protected abstract String getNode();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public abstract boolean isDefault();
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getFullNode();
|
||||
}
|
||||
|
||||
public boolean hasParent()
|
||||
{
|
||||
return getParent() != null;
|
||||
}
|
||||
|
||||
public MortarPermission getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(MortarPermission parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public boolean has(CommandSender sender)
|
||||
{
|
||||
return sender.hasPermission(getFullNode());
|
||||
}
|
||||
}
|
||||
@@ -1,620 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.IO;
|
||||
import com.volmit.iris.util.J;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.M;
|
||||
|
||||
public abstract class MortarPlugin extends JavaPlugin implements Listener
|
||||
{
|
||||
private KMap<KList<String>, VirtualCommand> commands;
|
||||
private KList<MortarCommand> commandCache;
|
||||
private KList<MortarPermission> permissionCache;
|
||||
private KMap<String, IController> controllers;
|
||||
private KList<IController> cachedControllers;
|
||||
private KMap<Class<? extends IController>, IController> cachedClassControllers;
|
||||
|
||||
public void l(Object l)
|
||||
{
|
||||
Iris.info("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
public void w(Object l)
|
||||
{
|
||||
Iris.warn("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
public void f(Object l)
|
||||
{
|
||||
Iris.error("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
public void v(Object l)
|
||||
{
|
||||
Iris.verbose("[" + getName() + "]: " + l);
|
||||
}
|
||||
|
||||
public void onEnable()
|
||||
{
|
||||
registerInstance();
|
||||
registerPermissions();
|
||||
registerCommands();
|
||||
registerControllers();
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::tickControllers, 0, 0);
|
||||
J.a(() -> outputInfo());
|
||||
registerListener(this);
|
||||
start();
|
||||
}
|
||||
|
||||
public void unregisterAll()
|
||||
{
|
||||
stopControllers();
|
||||
unregisterListeners();
|
||||
unregisterCommands();
|
||||
unregisterPermissions();
|
||||
unregisterInstance();
|
||||
}
|
||||
|
||||
private void outputInfo()
|
||||
{
|
||||
try
|
||||
{
|
||||
IO.delete(getDataFolder("info"));
|
||||
getDataFolder("info").mkdirs();
|
||||
outputPluginInfo();
|
||||
outputCommandInfo();
|
||||
outputPermissionInfo();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void outputPermissionInfo() throws IOException
|
||||
{
|
||||
FileConfiguration fc = new YamlConfiguration();
|
||||
|
||||
for(MortarPermission i : permissionCache)
|
||||
{
|
||||
chain(i, fc);
|
||||
}
|
||||
|
||||
fc.save(getDataFile("info", "permissions.yml"));
|
||||
}
|
||||
|
||||
private void chain(MortarPermission i, FileConfiguration fc)
|
||||
{
|
||||
KList<String> ff = new KList<String>();
|
||||
|
||||
for(MortarPermission j : i.getChildren())
|
||||
{
|
||||
ff.add(j.getFullNode());
|
||||
}
|
||||
|
||||
fc.set(i.getFullNode().replaceAll("\\Q.\\E", ",") + "." + "description", i.getDescription());
|
||||
fc.set(i.getFullNode().replaceAll("\\Q.\\E", ",") + "." + "default", i.isDefault());
|
||||
fc.set(i.getFullNode().replaceAll("\\Q.\\E", ",") + "." + "children", ff);
|
||||
|
||||
for(MortarPermission j : i.getChildren())
|
||||
{
|
||||
chain(j, fc);
|
||||
}
|
||||
}
|
||||
|
||||
private void outputCommandInfo() throws IOException
|
||||
{
|
||||
FileConfiguration fc = new YamlConfiguration();
|
||||
|
||||
for(MortarCommand i : commandCache)
|
||||
{
|
||||
chain(i, "/", fc);
|
||||
}
|
||||
|
||||
fc.save(getDataFile("info", "commands.yml"));
|
||||
}
|
||||
|
||||
private void chain(MortarCommand i, String c, FileConfiguration fc)
|
||||
{
|
||||
String n = c + (c.length() == 1 ? "" : " ") + i.getNode();
|
||||
fc.set(n + "." + "description", i.getDescription());
|
||||
fc.set(n + "." + "required-permissions", i.getRequiredPermissions());
|
||||
fc.set(n + "." + "aliases", i.getAllNodes());
|
||||
|
||||
for(MortarCommand j : i.getChildren())
|
||||
{
|
||||
chain(j, n, fc);
|
||||
}
|
||||
}
|
||||
|
||||
private void outputPluginInfo() throws IOException
|
||||
{
|
||||
FileConfiguration fc = new YamlConfiguration();
|
||||
fc.set("version", getDescription().getVersion());
|
||||
fc.set("name", getDescription().getName());
|
||||
fc.save(getDataFile("info", "plugin.yml"));
|
||||
}
|
||||
|
||||
private void registerPermissions()
|
||||
{
|
||||
permissionCache = new KList<>();
|
||||
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Permission.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
MortarPermission pc = (MortarPermission) i.getType().getConstructor().newInstance();
|
||||
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, pc);
|
||||
registerPermission(pc);
|
||||
permissionCache.add(pc);
|
||||
v("Registered Permissions " + pc.getFullNode() + " (" + i.getName() + ")");
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e)
|
||||
{
|
||||
w("Failed to register permission (field " + i.getName() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(org.bukkit.permissions.Permission i : computePermissions())
|
||||
{
|
||||
try
|
||||
{
|
||||
Bukkit.getPluginManager().addPermission(i);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private KList<org.bukkit.permissions.Permission> computePermissions()
|
||||
{
|
||||
KList<org.bukkit.permissions.Permission> g = new KList<>();
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Permission.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
MortarPermission x = (MortarPermission) i.get(Modifier.isStatic(i.getModifiers()) ? null : this);
|
||||
g.add(toPermission(x));
|
||||
g.addAll(computePermissions(x));
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | SecurityException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return g.removeDuplicates();
|
||||
}
|
||||
|
||||
private KList<org.bukkit.permissions.Permission> computePermissions(MortarPermission p)
|
||||
{
|
||||
KList<org.bukkit.permissions.Permission> g = new KList<>();
|
||||
|
||||
if(p == null)
|
||||
{
|
||||
return g;
|
||||
}
|
||||
|
||||
for(MortarPermission i : p.getChildren())
|
||||
{
|
||||
if(i == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
g.add(toPermission(i));
|
||||
g.addAll(computePermissions(i));
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
private org.bukkit.permissions.Permission toPermission(MortarPermission p)
|
||||
{
|
||||
if(p == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
org.bukkit.permissions.Permission perm = new org.bukkit.permissions.Permission(p.getFullNode() + (p.hasParent() ? "" : ".*"));
|
||||
perm.setDescription(p.getDescription() == null ? "" : p.getDescription());
|
||||
perm.setDefault(p.isDefault() ? PermissionDefault.TRUE : PermissionDefault.OP);
|
||||
|
||||
for(MortarPermission i : p.getChildren())
|
||||
{
|
||||
perm.getChildren().put(i.getFullNode(), true);
|
||||
}
|
||||
|
||||
return perm;
|
||||
}
|
||||
|
||||
private void registerPermission(MortarPermission pc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
stop();
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
unregisterListener(this);
|
||||
unregisterAll();
|
||||
}
|
||||
|
||||
private void tickControllers()
|
||||
{
|
||||
for(IController i : getControllers())
|
||||
{
|
||||
tickController(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void tickController(IController i)
|
||||
{
|
||||
if(i.getTickInterval() < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
M.tick++;
|
||||
if(M.interval(i.getTickInterval()))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.tick();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
w("Failed to tick controller " + i.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public KList<IController> getControllers()
|
||||
{
|
||||
return cachedControllers;
|
||||
}
|
||||
|
||||
private void registerControllers()
|
||||
{
|
||||
controllers = new KMap<>();
|
||||
cachedClassControllers = new KMap<>();
|
||||
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Control.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
IController pc = (IController) i.getType().getConstructor().newInstance();
|
||||
registerController(pc);
|
||||
i.set(this, pc);
|
||||
v("Registered " + pc.getName() + " (" + i.getName() + ")");
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e)
|
||||
{
|
||||
w("Failed to register controller (field " + i.getName() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cachedControllers = controllers.v();
|
||||
}
|
||||
|
||||
public IController getController(Class<? extends IController> c)
|
||||
{
|
||||
return cachedClassControllers.get(c);
|
||||
}
|
||||
|
||||
private void registerController(IController pc)
|
||||
{
|
||||
controllers.put(pc.getName(), pc);
|
||||
cachedClassControllers.put(pc.getClass(), pc);
|
||||
registerListener(pc);
|
||||
|
||||
try
|
||||
{
|
||||
pc.start();
|
||||
v("Started " + pc.getName());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
w("Failed to start controller " + pc.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerInstance()
|
||||
{
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Instance.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, this);
|
||||
v("Registered Instance " + i.getName());
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | SecurityException e)
|
||||
{
|
||||
w("Failed to register instance (field " + i.getName() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterInstance()
|
||||
{
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Instance.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
i.set(Modifier.isStatic(i.getModifiers()) ? null : this, null);
|
||||
v("Unregistered Instance " + i.getName());
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | SecurityException e)
|
||||
{
|
||||
w("Failed to unregister instance (field " + i.getName() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommands()
|
||||
{
|
||||
commands = new KMap<>();
|
||||
commandCache = new KList<>();
|
||||
|
||||
for(Field i : getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(com.volmit.iris.command.util.Command.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
i.setAccessible(true);
|
||||
MortarCommand pc = (MortarCommand) i.getType().getConstructor().newInstance();
|
||||
com.volmit.iris.command.util.Command c = i.getAnnotation(com.volmit.iris.command.util.Command.class);
|
||||
registerCommand(pc, c.value());
|
||||
commandCache.add(pc);
|
||||
v("Registered Commands /" + pc.getNode() + " (" + i.getName() + ")");
|
||||
}
|
||||
|
||||
catch(IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e)
|
||||
{
|
||||
w("Failed to register command (field " + i.getName() + ")");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args)
|
||||
{
|
||||
KList<String> chain = new KList<String>();
|
||||
chain.add(args);
|
||||
|
||||
for(KList<String> i : commands.k())
|
||||
{
|
||||
for(String j : i)
|
||||
{
|
||||
if(j.equalsIgnoreCase(label))
|
||||
{
|
||||
VirtualCommand cmd = commands.get(i);
|
||||
|
||||
if(cmd.hit(sender, chain.copy(), label))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void registerCommand(ICommand cmd)
|
||||
{
|
||||
registerCommand(cmd, "");
|
||||
}
|
||||
|
||||
public void registerCommand(ICommand cmd, String subTag)
|
||||
{
|
||||
commands.put(cmd.getAllNodes(), new VirtualCommand(cmd, subTag.trim().isEmpty() ? getTag() : getTag(subTag.trim())));
|
||||
PluginCommand cc = getCommand(cmd.getNode().toLowerCase());
|
||||
|
||||
if(cc != null)
|
||||
{
|
||||
cc.setExecutor(this);
|
||||
cc.setUsage(getName() + ":" + getClass().toString() + ":" + cmd.getNode());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
RouterCommand r = new RouterCommand(cmd, this);
|
||||
r.setUsage(getName() + ":" + getClass().toString());
|
||||
((CommandMap) new com.volmit.iris.util.V(Bukkit.getServer()).get("commandMap")).register("", r);
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterCommand(ICommand cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
SimpleCommandMap m = new com.volmit.iris.util.V(Bukkit.getServer()).get("commandMap");
|
||||
|
||||
Map<String, Command> k = new com.volmit.iris.util.V(m).get("knownCommands");
|
||||
|
||||
for(Iterator<Map.Entry<String, Command>> it = k.entrySet().iterator(); it.hasNext();)
|
||||
{
|
||||
Map.Entry<String, Command> entry = it.next();
|
||||
if(entry.getValue() instanceof Command)
|
||||
{
|
||||
org.bukkit.command.Command c = (org.bukkit.command.Command) entry.getValue();
|
||||
String u = c.getUsage();
|
||||
|
||||
if(u != null && u.equals(getName() + ":" + getClass().toString() + ":" + cmd.getNode()))
|
||||
{
|
||||
if(c.unregister(m))
|
||||
{
|
||||
it.remove();
|
||||
v("Unregistered Command /" + cmd.getNode());
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(getTag() + "Failed to unregister command " + c.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return getTag("");
|
||||
}
|
||||
|
||||
public void registerListener(Listener l)
|
||||
{
|
||||
Bukkit.getPluginManager().registerEvents(l, this);
|
||||
}
|
||||
|
||||
public void unregisterListener(Listener l)
|
||||
{
|
||||
HandlerList.unregisterAll(l);
|
||||
}
|
||||
|
||||
public void unregisterListeners()
|
||||
{
|
||||
HandlerList.unregisterAll((Listener) this);
|
||||
}
|
||||
|
||||
public void unregisterCommands()
|
||||
{
|
||||
for(VirtualCommand i : commands.v())
|
||||
{
|
||||
try
|
||||
{
|
||||
unregisterCommand(i.getCommand());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterPermissions()
|
||||
{
|
||||
for(org.bukkit.permissions.Permission i : computePermissions())
|
||||
{
|
||||
Bukkit.getPluginManager().removePermission(i);
|
||||
v("Unregistered Permission " + i.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void stopControllers()
|
||||
{
|
||||
for(IController i : controllers.v())
|
||||
{
|
||||
try
|
||||
{
|
||||
unregisterListener(i);
|
||||
i.stop();
|
||||
v("Stopped " + i.getName());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
w("Failed to stop controller " + i.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File getDataFile(String... strings)
|
||||
{
|
||||
File f = new File(getDataFolder(), new KList<String>(strings).toString(File.separator));
|
||||
f.getParentFile().mkdirs();
|
||||
return f;
|
||||
}
|
||||
|
||||
public File getDataFolder(String... strings)
|
||||
{
|
||||
if(strings.length == 0)
|
||||
{
|
||||
return super.getDataFolder();
|
||||
}
|
||||
|
||||
File f = new File(getDataFolder(), new KList<String>(strings).toString(File.separator));
|
||||
f.mkdirs();
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
|
||||
public abstract void stop();
|
||||
|
||||
public abstract String getTag(String subTag);
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Represents a volume sender. A command sender with extra crap in it
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public class MortarSender implements CommandSender
|
||||
{
|
||||
private CommandSender s;
|
||||
private String tag;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String command;
|
||||
|
||||
/**
|
||||
* Wrap a command sender
|
||||
*
|
||||
* @param s
|
||||
* the command sender
|
||||
*/
|
||||
public MortarSender(CommandSender s)
|
||||
{
|
||||
tag = "";
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public MortarSender(CommandSender s, String tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a command tag (prefix for sendMessage)
|
||||
*
|
||||
* @param tag
|
||||
* the tag
|
||||
*/
|
||||
public void setTag(String tag)
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command tag
|
||||
*
|
||||
* @return the command tag
|
||||
*/
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this sender a player?
|
||||
*
|
||||
* @return true if it is
|
||||
*/
|
||||
public boolean isPlayer()
|
||||
{
|
||||
return getS() instanceof Player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force cast to player (be sure to check first)
|
||||
*
|
||||
* @return a casted player
|
||||
*/
|
||||
public Player player()
|
||||
{
|
||||
return (Player) getS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin sender this object is wrapping
|
||||
*
|
||||
* @return the command sender
|
||||
*/
|
||||
public CommandSender getS()
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name)
|
||||
{
|
||||
return s.isPermissionSet(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm)
|
||||
{
|
||||
return s.isPermissionSet(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name)
|
||||
{
|
||||
return s.hasPermission(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm)
|
||||
{
|
||||
return s.hasPermission(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
|
||||
{
|
||||
return s.addAttachment(plugin, name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin)
|
||||
{
|
||||
return s.addAttachment(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks)
|
||||
{
|
||||
return s.addAttachment(plugin, name, value, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks)
|
||||
{
|
||||
return s.addAttachment(plugin, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment)
|
||||
{
|
||||
s.removeAttachment(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions()
|
||||
{
|
||||
s.recalculatePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions()
|
||||
{
|
||||
return s.getEffectivePermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp()
|
||||
{
|
||||
return s.isOp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value)
|
||||
{
|
||||
s.setOp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message)
|
||||
{
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&', getTag()) + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String[] messages)
|
||||
{
|
||||
for(String str : messages)
|
||||
s.sendMessage(ChatColor.translateAlternateColorCodes('&', getTag() + str));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer()
|
||||
{
|
||||
return s.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return s.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spigot spigot()
|
||||
{
|
||||
return s.spigot();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RUNTIME)
|
||||
@Target(FIELD)
|
||||
public @interface Permission
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Assistive command router
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public class RouterCommand extends org.bukkit.command.Command
|
||||
{
|
||||
private CommandExecutor ex;
|
||||
private String usage;
|
||||
|
||||
/**
|
||||
* The router command routes commands to bukkit executors
|
||||
*
|
||||
* @param realCommand
|
||||
* the real command
|
||||
* @param ex
|
||||
* the executor
|
||||
*/
|
||||
public RouterCommand(ICommand realCommand, CommandExecutor ex)
|
||||
{
|
||||
super(realCommand.getNode().toLowerCase());
|
||||
setAliases(realCommand.getNodes());
|
||||
|
||||
this.ex = ex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command setUsage(String u)
|
||||
{
|
||||
this.usage = u;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage()
|
||||
{
|
||||
return usage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args)
|
||||
{
|
||||
return ex.onCommand(sender, this, commandLabel, args);
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
package com.volmit.iris.command.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import com.volmit.iris.util.V;
|
||||
|
||||
/**
|
||||
* Represents a virtual command. A chain of iterative processing through
|
||||
* subcommands.
|
||||
*
|
||||
* @author cyberpwn
|
||||
*
|
||||
*/
|
||||
public class VirtualCommand
|
||||
{
|
||||
private ICommand command;
|
||||
private String tag;
|
||||
|
||||
private KMap<KList<String>, VirtualCommand> children;
|
||||
|
||||
public VirtualCommand(ICommand command)
|
||||
{
|
||||
this(command, "");
|
||||
}
|
||||
|
||||
public VirtualCommand(ICommand command, String tag)
|
||||
{
|
||||
this.command = command;
|
||||
children = new KMap<KList<String>, VirtualCommand>();
|
||||
this.tag = tag;
|
||||
|
||||
for(Field i : command.getClass().getDeclaredFields())
|
||||
{
|
||||
if(i.isAnnotationPresent(Command.class))
|
||||
{
|
||||
try
|
||||
{
|
||||
Command cc = i.getAnnotation(Command.class);
|
||||
ICommand cmd = (ICommand) i.getType().getConstructor().newInstance();
|
||||
new V(command, true, true).set(i.getName(), cmd);
|
||||
children.put(cmd.getAllNodes(), new VirtualCommand(cmd, cc.value().trim().isEmpty() ? tag : cc.value().trim()));
|
||||
}
|
||||
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
public ICommand getCommand()
|
||||
{
|
||||
return command;
|
||||
}
|
||||
|
||||
public KMap<KList<String>, VirtualCommand> getChildren()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
|
||||
public boolean hit(CommandSender sender, KList<String> chain)
|
||||
{
|
||||
return hit(sender, chain, null);
|
||||
}
|
||||
|
||||
public boolean hit(CommandSender sender, KList<String> chain, String label)
|
||||
{
|
||||
MortarSender vs = new MortarSender(sender);
|
||||
vs.setTag(tag);
|
||||
|
||||
if(label != null)
|
||||
vs.setCommand(label);
|
||||
|
||||
if(chain.isEmpty())
|
||||
{
|
||||
if(!checkPermissions(sender, command))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return command.handle(vs, new String[0]);
|
||||
}
|
||||
|
||||
String nl = chain.get(0);
|
||||
|
||||
for(KList<String> i : children.k())
|
||||
{
|
||||
for(String j : i)
|
||||
{
|
||||
if(j.equalsIgnoreCase(nl))
|
||||
{
|
||||
vs.setCommand(chain.get(0));
|
||||
VirtualCommand cmd = children.get(i);
|
||||
KList<String> c = chain.copy();
|
||||
c.remove(0);
|
||||
if(cmd.hit(sender, c, vs.getCommand()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!checkPermissions(sender, command))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return command.handle(vs, chain.toArray(new String[chain.size()]));
|
||||
}
|
||||
|
||||
private boolean checkPermissions(CommandSender sender, ICommand command2)
|
||||
{
|
||||
boolean failed = false;
|
||||
|
||||
for(String i : command.getRequiredPermissions())
|
||||
{
|
||||
if(!sender.hasPermission(i))
|
||||
{
|
||||
failed = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> sender.sendMessage("- " + ChatColor.WHITE + i), 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(failed)
|
||||
{
|
||||
sender.sendMessage("Insufficient Permissions");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user