SteamWar/BauSystem
Archiviert
13
0
Dieser Commit ist enthalten in:
RedstoneTechnik 2019-02-14 19:59:43 +01:00
Commit 95bdfb3c11
40 geänderte Dateien mit 5510 neuen und 0 gelöschten Zeilen

52
WarShipFactory.iml Normale Datei
Datei anzeigen

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT">
<CLASSES>
<root url="jar://$MODULE_DIR$/../intellj/spigot-1.12.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="module-library">
<library name="Maven: com.sk89q.worldedit:worldedit-bukkit:6.1.7.3">
<CLASSES>
<root url="jar://$MODULE_DIR$/../intellj/worldedit-bukkit-6.1.7.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.sk89q.worldguard:worldguard-bukkit:6.2">
<CLASSES>
<root url="jar://$MODULE_DIR$/../intellj/worldguard-6.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Maven: com.boydti:fawe-api:19.01.01-56a71fa-1244-22.0.6">
<CLASSES>
<root url="jar://$MODULE_DIR$/../intellj/FastAsyncWorldEdit-AllVersion.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.12" level="project" />
</component>
</module>

100
pom.xml Normale Datei
Datei anzeigen

@ -0,0 +1,100 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.quantumnanox</groupId>
<artifactId>WarShipFactory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WarShipFactory</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>sk89q-snapshots</id>
<url>http://maven.sk89q.com/artifactory/repo</url>
<releases>
<enabled>true</enabled> <!-- releases enabled: this specific repository also hosts release versions -->
</releases>
<snapshots>
<enabled>true</enabled> <!-- snapshots enabled: we declare a SNAPSHOT repository because we need
to download a SNAPSHOT dependency -->
</snapshots>
</repository>
<repository>
<id>fawe-repo</id>
<url>http://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.kt</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>C:\Users\andre\Desktop\intellj\spigot-1.12.2.jar</systemPath>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.7.3</version>
<scope>system</scope>
<systemPath>C:\Users\andre\Desktop\intellj\worldedit-bukkit-6.1.7.3.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>6.2</version>
<scope>system</scope>
<systemPath>C:\Users\andre\Desktop\intellj\worldguard-6.2.jar</systemPath>
</dependency>
<dependency>
<groupId>com.boydti</groupId>
<artifactId>fawe-api</artifactId>
<version>19.01.01-56a71fa-1244-22.0.6</version>
<scope>system</scope>
<systemPath>C:\Users\andre\Desktop\intellj\FastAsyncWorldEdit-AllVersion.jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.12</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Datei anzeigen

@ -0,0 +1,99 @@
package de.pro_crafting.commandframework;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.command.CommandException;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.Plugin;
/**
* Command Framework - BukkitCommand <br>
* An implementation of Bukkit's Command class allowing for registering of
* commands without plugin.yml
*
* @author minnymin3
*
*/
public class BukkitCommand extends org.bukkit.command.Command {
private final Plugin owningPlugin;
private CommandExecutor executor;
protected BukkitCompleter completer;
/**
* A slimmed down PluginCommand
*
* @param name
* @param owner
*/
protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
super(label);
this.executor = executor;
this.owningPlugin = owner;
this.usageMessage = "";
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
boolean success = false;
if (!owningPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = executor.onCommand(sender, this, commandLabel, args);
} catch (Throwable ex) {
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin "
+ owningPlugin.getDescription().getFullName(), ex);
}
if (!success && usageMessage.length() > 0) {
for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args)
throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ")
.append(owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
}

Datei anzeigen

@ -0,0 +1,64 @@
package de.pro_crafting.commandframework;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
/**
* Command Framework - BukkitCompleter <br>
* An implementation of the TabCompleter class allowing for multiple tab
* completers per command
*
* @author minnymin3
*
*/
public class BukkitCompleter implements TabCompleter {
private Map<String, Entry<Method, Object>> completers = new HashMap<String, Entry<Method, Object>>();
public void addCompleter(String label, Method m, Object obj) {
completers.put(label, new AbstractMap.SimpleEntry<Method, Object>(m, obj));
}
@SuppressWarnings("unchecked")
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
if (!args[x].equals("") && !args[x].equals(" ")) {
buffer.append("." + args[x].toLowerCase());
}
}
String cmdLabel = buffer.toString();
if (completers.containsKey(cmdLabel)) {
Entry<Method, Object> entry = completers.get(cmdLabel);
try {
List<String> labelParts = (List<String>) entry.getKey().invoke(entry.getValue(),
new CommandArgs(sender, command, cmdLabel, args, cmdLabel.split("\\.").length - 1));
if (labelParts == null || labelParts.size() == 0)
{
return null;
}
return labelParts;
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return null;
}
}

Datei anzeigen

@ -0,0 +1,72 @@
package de.pro_crafting.commandframework;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Command Framework - Command <br>
* The command annotation used to designate methods as commands. All methods
* should have a single CommandArgs argument
*
* @author minnymin3
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
/**
* The name of the command. If it is a sub command then its values would be
* separated by periods. ie. a command that would be a subcommand of test
* would be 'test.subcommandname'
*
* @return
*/
public String name();
/**
* Gets the required permission of the command
*
* @return
*/
public String permission() default "";
/**
* The message sent to the player when they do not have permission to
* execute it
*
* @return
*/
public String noPerm() default "You do not have permission to perform that action";
/**
* A list of alternate names that the command is executed under. See
* name() for details on how names work
*
* @return
*/
public String[] aliases() default {};
/**
* The description that will appear in /help of the command
*
* @return
*/
public String description() default "";
/**
* The usage that will appear in /help (commandname)
*
* @return
*/
public String usage() default "";
/**
* Whether or not the command is available to players only
*
* @return
*/
public boolean inGameOnly() default false;
}

Datei anzeigen

@ -0,0 +1,107 @@
package de.pro_crafting.commandframework;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
* Command Framework - CommandArgs <br>
* This class is passed to the command methods and contains various utilities as
* well as the command info.
*
* @author minnymin3
*
*/
public class CommandArgs {
private CommandSender sender;
private org.bukkit.command.Command command;
private String label;
private String[] args;
protected CommandArgs(CommandSender sender, org.bukkit.command.Command command, String label, String[] args,
int subCommand) {
String[] modArgs = new String[args.length - subCommand];
for (int i = 0; i < args.length - subCommand; i++) {
modArgs[i] = args[i + subCommand];
}
StringBuffer buffer = new StringBuffer();
buffer.append(label);
for (int x = 0; x < subCommand; x++) {
buffer.append("." + args[x]);
}
String cmdLabel = buffer.toString();
this.sender = sender;
this.command = command;
this.label = cmdLabel;
this.args = modArgs;
}
/**
* Gets the command sender
*
* @return
*/
public CommandSender getSender() {
return sender;
}
/**
* Gets the original command object
*
* @return
*/
public org.bukkit.command.Command getCommand() {
return command;
}
/**
* Gets the label including sub command labels of this command
*
* @return Something like 'test.subcommand'
*/
public String getLabel() {
return label;
}
/**
* Gets all the arguments after the command's label. ie. if the command
* label was test.subcommand and the arguments were subcommand foo foo, it
* would only return 'foo foo' because 'subcommand' is part of the command
*
* @return
*/
public String[] getArgs() {
return args;
}
/**
* Gets the argument at the specified index
* @param index The index to get
* @return The string at the specified index
*/
public String getArgs(int index) {
return args[index];
}
/**
* Returns the length of the command arguments
* @return int length of args
*/
public int length() {
return args.length;
}
public boolean isPlayer() {
return sender instanceof Player;
}
public Player getPlayer() {
if (sender instanceof Player) {
return (Player) sender;
} else {
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,257 @@
package de.pro_crafting.commandframework;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.help.GenericCommandHelpTopic;
import org.bukkit.help.HelpTopic;
import org.bukkit.help.HelpTopicComparator;
import org.bukkit.help.IndexHelpTopic;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.SimplePluginManager;
/**
* Command Framework - CommandFramework <br>
* The main command framework class used for controlling the framework.
*
* @author minnymin3
*
*/
public class CommandFramework implements CommandExecutor {
private Map<String, Entry<Method, Object>> commandMap = new HashMap<String, Entry<Method, Object>>();
private CommandMap map;
private Plugin plugin;
private String noPermMessage = null;
private String inGameOnlyMessage;
/**
* Initializes the command framework and sets up the command maps
*/
public CommandFramework(Plugin plugin) {
this.plugin = plugin;
if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
try {
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
map = (CommandMap) field.get(manager);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
this.inGameOnlyMessage = "This command is only performable in game";
}
public String[] getCommandLabels()
{
return this.commandMap.keySet().toArray(new String[0]);
}
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
return handleCommand(sender, cmd, label, args);
}
/**
* Handles commands. Used in the onCommand method in your JavaPlugin class
*
* @param sender The {@link org.bukkit.command.CommandSender} parsed from
* onCommand
* @param cmd The {@link org.bukkit.command.Command} parsed from onCommand
* @param label The label parsed from onCommand
* @param args The arguments parsed from onCommand
* @return Always returns true for simplicity's sake in onCommand
*/
public boolean handleCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
buffer.append(".").append(args[x].toLowerCase());
}
String cmdLabel = buffer.toString();
if (commandMap.containsKey(cmdLabel)) {
Method method = commandMap.get(cmdLabel).getKey();
Object methodObject = commandMap.get(cmdLabel).getValue();
Command command = method.getAnnotation(Command.class);
if (command.permission() != null && !command.permission().isEmpty() && !sender.hasPermission(command.permission())) {
if(!command.noPerm().equals("You do not have permission to perform that action") || this.noPermMessage == null){
sender.sendMessage(command.noPerm());
return true;
}
sender.sendMessage(this.noPermMessage);
return true;
}
if (command.inGameOnly() && !(sender instanceof Player)) {
sender.sendMessage(this.inGameOnlyMessage);
return true;
}
try {
method.invoke(methodObject, new CommandArgs(sender, cmd, label, args,
cmdLabel.split("\\.").length - 1));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return true;
}
}
defaultCommand(new CommandArgs(sender, cmd, label, args, 0));
return true;
}
public void setNoPermMessage(String message){
this.noPermMessage = message;
}
public String getNoPermMessage(){
return this.noPermMessage;
}
/**
* Registers all command and completer methods inside of the object. Similar
* to Bukkit's registerEvents method.
*
* @param obj The object to register the commands of
*/
public void registerCommands(Object obj) {
for (Method m : obj.getClass().getMethods()) {
if (m.getAnnotation(Command.class) != null) {
Command command = m.getAnnotation(Command.class);
if (m.getParameterTypes().length != 1 || m.getParameterTypes()[0] != CommandArgs.class) {
plugin.getLogger().warning("Unable to register command " + m.getName() +
". Unexpected method arguments");
continue;
}
registerCommand(command, command.name(), m, obj);
for (String alias : command.aliases()) {
registerCommand(command, alias, m, obj);
}
} else if (m.getAnnotation(Completer.class) != null) {
Completer comp = m.getAnnotation(Completer.class);
if (m.getParameterTypes().length > 1 || m.getParameterTypes().length == 0 || m.getParameterTypes()[0] != CommandArgs.class) {
plugin.getLogger().warning("Unable to register tab completer " + m.getName() +
". Unexpected method arguments");
continue;
}
if (m.getReturnType() != List.class) {
plugin.getLogger().warning("Unable to register command " + m.getName() +
". Unexpected return type");
continue;
}
registerCompleter(comp.name(), m, obj);
for (String alias : comp.aliases()) {
registerCompleter(alias, m, obj);
}
}
}
}
/**
* Registers all the commands under the plugin's help
*/
public void registerHelp() {
Set<HelpTopic> help = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance());
for (String s : commandMap.keySet()) {
if (!s.contains(".")) {
org.bukkit.command.Command cmd = map.getCommand(s);
HelpTopic topic = new GenericCommandHelpTopic(cmd);
help.add(topic);
}
}
IndexHelpTopic topic = new IndexHelpTopic(plugin.getName(), "All commands for " + plugin.getName(), null, help,
"Below is a list of all " + plugin.getName() + " commands:");
Bukkit.getServer().getHelpMap().addTopic(topic);
}
public void registerCommand(Command command, String label, Method m, Object obj) {
commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry<Method, Object>(m, obj));
commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(), new AbstractMap.SimpleEntry<Method, Object>(m, obj));
String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), cmd);
}
if (!command.description().equalsIgnoreCase("") && cmdLabel.equals(label)) {
map.getCommand(cmdLabel).setDescription(command.description());
}
if (!command.usage().equalsIgnoreCase("") && cmdLabel.equals(label)) {
map.getCommand(cmdLabel).setUsage(command.usage());
}
}
public void registerCompleter(String label, Method m, Object obj) {
String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), command);
}
if (map.getCommand(cmdLabel) instanceof BukkitCommand) {
BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel);
if (command.completer == null) {
command.completer = new BukkitCompleter();
}
command.completer.addCompleter(label, m, obj);
} else if (map.getCommand(cmdLabel) instanceof PluginCommand) {
try {
Object command = map.getCommand(cmdLabel);
Field field = command.getClass().getDeclaredField("completer");
field.setAccessible(true);
if (field.get(command) == null) {
BukkitCompleter completer = new BukkitCompleter();
completer.addCompleter(label, m, obj);
field.set(command, completer);
} else if (field.get(command) instanceof BukkitCompleter) {
BukkitCompleter completer = (BukkitCompleter) field.get(command);
completer.addCompleter(label, m, obj);
} else {
plugin.getLogger().warning("Unable to register tab completer " + m.getName()
+ ". A tab completer is already registered for that command!");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void defaultCommand(CommandArgs args) {
args.getSender().sendMessage(args.getLabel() + " is not handled! Oh noes!");
}
public String getInGameOnlyMessage() {
return this.inGameOnlyMessage;
}
public void setInGameOnlyMessage(String inGameOnlyMessage) {
this.inGameOnlyMessage = inGameOnlyMessage;
}
}

Datei anzeigen

@ -0,0 +1,38 @@
package de.pro_crafting.commandframework;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Command Framework - Completer <br>
* The completer annotation used to designate methods as command completers. All
* methods should have a single CommandArgs argument and return a String List
* object
*
* @author minnymin3
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Completer {
/**
* The command that this completer completes. If it is a sub command then
* its values would be separated by periods. ie. a command that would be a
* subcommand of test would be 'test.subcommandname'
*
* @return
*/
String name();
/**
* A list of alternate names that the completer is executed under. See
* name() for details on how names work
*
* @return
*/
String[] aliases() default {};
}

Datei anzeigen

@ -0,0 +1,140 @@
package de.pro_crafting.sawe;
import java.sql.SQLException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class RegionListener implements Listener {
private JavaPlugin plugin;
public RegionListener(JavaPlugin plugin) {
this.plugin = plugin;
this.plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void playerCommandHandler(PlayerCommandPreprocessEvent event) {
WorldEditPlugin we = (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
String command = event.getMessage().split(" ")[0];
if (!isWorldEditCommand(command)) {
return;
}
Player p = event.getPlayer();
try {
if (p.hasPermission("bau.team")) {
return;
}
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage("§cDu darfst hier kein Worldedit benutzen.");
event.setCancelled(true);
return;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp != null) {
if (wp.canWorldEdit == false || fw == null) {
p.sendMessage("§cDu darfst hier kein Worldedit benutzen.");
event.setCancelled(true);
}
} else {
if (fw.getOwner().equals(p.getUniqueId())) {
return;
}
p.sendMessage("§cDu darfst hier kein Worldedit benutzen.");
event.setCancelled(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlock(BlockBreakEvent e) {
Player p = e.getPlayer();
try {
if (p.hasPermission("bau.team")) {
return;
}
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage("§cDu darfst nicht bauen.");
e.setCancelled(true);
return;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp != null) {
if (wp.canBuild == false) {
p.sendMessage("§cDu darfst nicht bauen.");
e.setCancelled(true);
}
} else {
if (fw.getOwner().equals(p.getUniqueId())) {
return;
}
e.setCancelled(true);
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onB(BlockPlaceEvent e) throws SQLException {
Player p = e.getPlayer();
if (p.hasPermission("bau.team")) {
return;
}
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage("§cDu darfst nicht bauen.");
e.setCancelled(true);
return;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp != null) {
if (wp.canBuild == false) {
p.sendMessage("§cDu darfst nicht bauen.");
e.setCancelled(true);
}
} else {
if (fw.getOwner().equals(p.getUniqueId())) {
return;
}
e.setCancelled(true);
}
}
private boolean isWorldEditCommand(String command) {
if (command.startsWith("/")) {
command = command.replaceFirst("/", "");
}
command = command.toLowerCase();
return ((WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit")).getWorldEdit().getPlatformManager()
.getCommandManager().getDispatcher().get(command) != null;
}
@EventHandler
public void onExplode(EntityExplodeEvent e) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(e.getEntity().getWorld().getName());
if (fw != null) {
if (fw.isTntDamage() == false) e.setCancelled(true);
}
}
}

Datei anzeigen

@ -0,0 +1,809 @@
package de.quantumnanox.warshipfactory.commands;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.io.IOException;
import java.sql.SQLException;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.sk89q.worldedit.CuboidClipboard;
import com.boydti.fawe.util.EditSessionBuilder;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.quantumnanox.warshipfactory.config.Config;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import de.pro_crafting.commandframework.Command;
import de.quantumnanox.warshipfactory.content.UUIDFetcher;
import de.pro_crafting.commandframework.CommandArgs;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import sun.security.x509.UniqueIdentity;
public class CommandBau {
public Config config;
@Command(name = "bau")
public void onBau(CommandArgs args) {
CommandSender s = args.getSender();
s.sendMessage(WarShipFactory.S_PREFIX + "WarShipFactory by Exceptionflug v" + WarShipFactory.getInstance().getDescription().getVersion());
s.sendMessage(WarShipFactory.S_PREFIX + "Um eine Liste mit Befehlen zu erhalten, gib §t/bau help §7ein.");
}
@Command(name = "bau.help", inGameOnly = true)
public void onHelp(CommandArgs args) {
Player p = args.getPlayer();
p.sendMessage(WarShipFactory.S_PREFIX + "Hilfe:");
p.sendMessage("§8/bau - §6Zeigt dir Infos über das Plugin");
p.sendMessage("§8/bau help - §6Zeigt dir diese Liste");
p.sendMessage("§8/bau home - §6Teleportiert dich auf deine Welt");
p.sendMessage("§8/bau addmember - §6Fügt einen Spieler zu deiner Welt hinzu");
p.sendMessage("§8/bau delmember - §6Entfernt einen Spieler von deiner Welt");
p.sendMessage("§8/bau togglewe - §6Ändert den Zustand für: Darf ein Spieler WorldEdit verwenden?");
p.sendMessage("§8/bau togglebuild - §6Ändert den Zustand für: Darf ein Spieler bauen?");
p.sendMessage("§8/bau toggletp - §6Ändert den Zustand für: Darf ein Spieler sich teleportieren?");
p.sendMessage("§8/bau toggletestblock - §6Ändert den Zustand für : Darf ein Spieler einen TestBlock erneuern");
p.sendMessage("§8/bau togglereset - §6Ändert den Zustand für : Darf ein Spieler eine Region erneuern");
p.sendMessage("§8/bau toggleresetall - §6Ändert den Zustand für : Darf ein Spieler eine ganze Welt erneuern");
p.sendMessage("§8/bau togglereplace - §6Ändert den Zustand für : Darf ein Spieler in einer Region replacen");
p.sendMessage("§8/bau togglechgm - §6Ändert den Zustand für: Darf ein Spieler seinen Spielmodus ändern?");
p.sendMessage("§8/bau tntdmg - §6Erlaubt / verbietet TNT Explosionen");
p.sendMessage("§8/bau testblock - §6Erneuert einen Testblock in der umgebung");
p.sendMessage("§8/bau reset - §6Setzt eine region zurück wo man sich befindet");
p.sendMessage("§8/bau resetall - §6Resetet deine komplette Welt");
p.sendMessage("§8/bau replace - §6Ersetzt in einer Region Obsidian zu TNT und Bedrock zu Schleim");
p.sendMessage("§8/bau tp - §6Teleportiert dich auf eine Welt");
p.sendMessage("§8/bau info - §6Zeigt dir Infos über die aktuelle Welt");
p.sendMessage("§8/bau gui - §6Öffnet eine GUI");
}
@Command(name = "bau.home", inGameOnly = true)
public void onHome(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
fw = new FactoryWorld(p.getUniqueId());
WarShipFactory.getInstance().factoryWorlds.register(fw);
}
if (fw.isLoading()) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cEinen Moment Geduld! Die Welt lädt...");
return;
}
if (fw.getWrapped() == null) {
try {
p.sendMessage(WarShipFactory.S_PREFIX + "§aEinen Moment bitte... Deine Welt wird vorbereitet.");
fw.loadWorld();
} catch (Exception e) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cBeim Laden der Welt ist ein Fehler aufgetreten.");
e.printStackTrace();
}
}
p.teleport(fw.getWrapped().getSpawnLocation());
p.getInventory().clear();
Bukkit.getScheduler().scheduleSyncDelayedTask(WarShipFactory.getInstance(), new Runnable() {
public void run() {
p.setGameMode(GameMode.CREATIVE);
}
}, 20L);
}
@Command(name = "bau.addmember", inGameOnly = true)
public void onAdd(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast noch keine Welt.");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau addmember <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
if (fw.getMember(id) != null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDieser Spieler ist bereits Mitglied auf deiner Welt");
return;
}
WorldPlayer wp = new WorldPlayer(id, fw);
wp.canBuild = true;
fw.getMembers().register(wp);
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler wurde zu deiner Welt hinzugefügt.");
}
@Command(name = "bau.delmember", inGameOnly = true)
public void onDel(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast noch keine Welt.");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau delmember <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
if (fw.getMember(id) == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDieser Spieler ist kein Mitglied auf deiner Welt");
return;
}
fw.getMembers().unregister(fw.getMembers().getID(fw.getMember(id)));
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler wurde entfernt.");
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (z.getWorld().getUID().equals(fw.getWrapped().getUID())) {
z.teleport(WarShipFactory.getInstance().config.spawn);
z.getInventory().clear();
}
}
}
@Command(name = "bau.tp", inGameOnly = true)
public void onTp(CommandArgs args) {
Player p = args.getPlayer();
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau tp <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(id);
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler hat keine Welt");
return;
}
try {
if (!p.hasPermission("bau.team")) {
if (fw.getMember(p.getUniqueId()) == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu bist kein Mitglied dieser Welt");
return;
}
}
if (fw.getWrapped() == null) {
fw.loadWorld();
}
p.getInventory().clear();
p.teleport(fw.getWrapped().getSpawnLocation());
Bukkit.getScheduler().scheduleSyncDelayedTask(WarShipFactory.getInstance(), new Runnable() {
public void run() {
p.setGameMode(GameMode.CREATIVE);
}
}, 20);
p.sendMessage(WarShipFactory.S_PREFIX + "§aDu wurdest teleportiert.");
} catch (IOException e) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cFehla.");
e.printStackTrace();
}
}
@Command(name = "bau.gui", inGameOnly = true)
public boolean ongui(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return false;
} else {
Inventory inv = Bukkit.createInventory(null, 9, "§aBau Optionen");
ItemStack bau = new ItemStack(Material.COMPASS);
ItemMeta meta = bau.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bBau Abteilungen");
bau.setItemMeta(meta);
inv.addItem(bau);
ItemStack optionen = new ItemStack(Material.ENCHANTED_BOOK);
meta = optionen.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWelten Optionen");
optionen.setItemMeta(meta);
inv.setItem(8, optionen);
ItemStack spieler = new ItemStack(Material.REDSTONE_BLOCK);
meta = spieler.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bSpieler Optionen");
spieler.setItemMeta(meta);
inv.setItem(4, spieler);
p.openInventory(inv);
return true;
}
}
@Command(name = "bau.togglewe", inGameOnly = true)
public void onToggleWE(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau togglewe <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canWorldEdit = !wp.canWorldEdit;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canWorldEdit) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a WorldEdit verwenden.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c WorldEdit verwenden.");
}
}
if (wp.canWorldEdit) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf WorldEdit verwenden.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf kein WorldEdit verwenden.");
}
}
@Command(name = "bau.toggletp", inGameOnly = true)
public void onToggleTP(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau toggletp <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canTeleport = !wp.canTeleport;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canTeleport) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a /tp verwenden.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c /tp verwenden.");
}
}
if (wp.canTeleport) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf sich teleportieren.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf sich nicht teleportieren.");
}
}
@Command(name = "bau.togglebuild", inGameOnly = true)
public void onToggleBD(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau togglebuild <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canBuild = !wp.canBuild;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canBuild) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a bauen.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c bauen.");
}
}
if (wp.canBuild) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf bauen.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf nicht bauen.");
}
}
@Command(name = "bau.togglechgm", inGameOnly = true)
public void onToggleCHG(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau togglechgm <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canChangeGamemode = !wp.canChangeGamemode;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canChangeGamemode) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a deinen Spielmodus ändern.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c deinen Spielmodus ändern.");
}
}
if (wp.canChangeGamemode) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf seinen Spielmodus ändern.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf nicht seinen Spielmodus ändern.");
}
}
@Command(name = "bau.toggletestblock", inGameOnly = true)
public void onToggleTestblock(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau toggletestblock <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canTestBlock = !wp.canTestBlock;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canTestBlock) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a die TestBlöcke erneuern.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c die TestBlöcke erneuern.");
}
}
if (wp.canTestBlock) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf nun deine TestBlöcke erneuern.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf keine TestBlöcke mehr reseten.");
}
}
@Command(name = "bau.togglereset", inGameOnly = true)
public void onTogglereset(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau togglereset <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canReset = !wp.canReset;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canReset) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a die Regionen erneuern.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c die Regionen erneuern.");
}
}
if (wp.canReset) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf nun deine Regionen erneuern.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf deine Regionen nicht mehr erneuern.");
}
}
@Command(name = "bau.toggleresetall", inGameOnly = true)
public void onToggleresetall(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau toggleresetall <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canResetAll = !wp.canResetAll;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canResetAll) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a die Welt erneuern.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c die Welt erneuern.");
}
}
if (wp.canResetAll) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf nun deine Welt erneuern.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf nun deine Welt nicht mehr erneuern.");
}
}
@Command(name = "bau.togglereplace", inGameOnly = true)
public void onTogglereplace(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
if (args.length() == 0) {
p.sendMessage(WarShipFactory.S_PREFIX + "§bBenutzung: /bau togglereplace <Spieler>");
return;
}
UUID id = UUIDFetcher.getUUID(args.getArgs(0));
if (id == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cUnbekannter Spieler");
return;
}
WorldPlayer wp = fw.getMember(id);
if (wp == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler ist kein Mitglied deiner Welt");
return;
}
wp.canReplace = !wp.canReplace;
Player z = Bukkit.getPlayer(id);
if (z != null) {
if (wp.canReplace) {
z.sendMessage(WarShipFactory.S_PREFIX + "§aDu kannst nun auf der Welt von §6" + p.getName() + "§a TNT und Schleim replacen.");
} else {
z.sendMessage(WarShipFactory.S_PREFIX + "§cDu kannst nun nicht mehr auf der Welt von §6" + p.getName() + "§c TNT und Schleim replacen.");
}
}
if (wp.canReplace) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aDer Spieler darf nun in diener Welt TNT und Schleim replacen.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDer Spieler darf nun in deiner Welt kein TNT und Schleim mehr replacen.");
}
}
@Command(name = "bau.testblock", inGameOnly = true)
public boolean ontestblock(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return false;
} else {
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canTestBlock == false) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du darfst den TestBlock nicht erneuern");
return false;
}
}
Location playerLocation = p.getLocation();
World playerWorld = p.getWorld();
@SuppressWarnings("unused")
int count = 0;
for (ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(playerWorld).getApplicableRegions(playerLocation)) {
count++;
String rgID = rg.getId().toString();
if(rgID.equalsIgnoreCase("resetall")) {
return true;
}
Vector position = new Vector(Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.X")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Y")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Z")));
File file = new File(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".schematic.testblock"));
pasteSchematic(p, file, position);
p.sendMessage(WarShipFactory.S_PREFIX + "Testblock erneuert!");
}
}
return false;
}
@Command(name = "bau.reset", inGameOnly = true)
public boolean onReset(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return false;
} else {
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canReset == false) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du darfst keine Regionen erneuern");
return false;
}
}
Location playerLocation = p.getLocation();
World playerWorld = p.getWorld();
@SuppressWarnings("unused")
int count = 0;
for (ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(playerWorld).getApplicableRegions(playerLocation)) {
count++;
String rgID = rg.getId().toString();
if(rgID.equalsIgnoreCase("resetall")) {
return true;
}
Vector position = new Vector(Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.X")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Y")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Z")));
File file = new File(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".schematic.reset"));
pasteSchematic(p, file, position);
p.sendMessage(WarShipFactory.S_PREFIX + "Region " + rgID + " wurde resettet!");
}
}
return false;
}
@Command(name = "bau.resetall", inGameOnly = true)
public boolean onresetall(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return false;
} else {
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canResetAll == false) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du darfst die Welt nicht erneuern");
return false;
}
}
for(Player ap : Bukkit.getOnlinePlayers()) {
if(ap.getWorld().getName() == fw.getWorldAddress()) {
Location location = new Location(Bukkit.getWorld("Bauspawn"), 1442, 113, 228, -151.9F, -4.2F);
ap.teleport(location);
ap.sendMessage(WarShipFactory.S_PREFIX + "Die Welt wird erneuert!");
}
}
fw.unloadWorld();
File directory = new File("plugins/WarShipFactory/worlds/" + fw.getWorldAddress());
del(directory);
FactoryWorld fw1 = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw1 == null) {
fw1 = new FactoryWorld(p.getUniqueId());
WarShipFactory.getInstance().factoryWorlds.register(fw1);
}
if (fw1.isLoading()) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cEinen Moment Geduld! Die Welt wird erneuert...");
return false;
}
if (fw.getWrapped() == null) {
try {
p.sendMessage(WarShipFactory.S_PREFIX + "§aEinen Moment bitte... Deine Welt wird vorbereitet.");
fw.loadWorld();
} catch (Exception e) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cBeim Laden der Welt ist ein Fehler aufgetreten.");
e.printStackTrace();
}
}
p.teleport(fw1.getWrapped().getSpawnLocation());
p.getInventory().clear();
Bukkit.getScheduler().scheduleSyncDelayedTask(WarShipFactory.getInstance(), new Runnable() {
public void run() {
p.setGameMode(GameMode.CREATIVE);
}
}, 20L);
}
return false;
}
@Command(name = "bau.replace", inGameOnly = true)
public boolean onreplace(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return false;
} else {
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canReplace == false) {
p.sendMessage("Du darfst in der Welt von " + p.getDisplayName() + " kein TNT und Schleim replacen!");
return false;
}
}
World world = p.getWorld();
int count = 0;
for(ProtectedRegion rg : WarShipFactory.getWorldGuard().getRegionManager(world).getApplicableRegions(p.getLocation())) {
count++;
if(count != 0) {
String rgID = rg.getId();
if(rgID.equalsIgnoreCase("resetall")) {
return true;
}
com.sk89q.worldedit.world.World weWorld = new BukkitWorld(p.getWorld());
EditSession editSession = WarShipFactory.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(p.getWorld()), Integer.MAX_VALUE);
CuboidSelection selection = new CuboidSelection(p.getWorld(), new Location(p.getWorld(), rg.getMinimumPoint().getBlockX(), rg.getMinimumPoint().getBlockY(), rg.getMinimumPoint().getBlockZ()), new Location(p.getWorld(), rg.getMaximumPoint().getBlockX(), rg.getMaximumPoint().getBlockY(), rg.getMaximumPoint().getBlockZ()));
Set<BaseBlock> targetObsidian = new HashSet<>();
targetObsidian.add(new BaseBlock(49));
Set<BaseBlock> targetBedrock = new HashSet<>();
targetBedrock.add(new BaseBlock(7));
try {
int tnt = editSession.replaceBlocks(selection.getRegionSelector().getRegion(), targetObsidian, new BaseBlock(46));
int slime = editSession.replaceBlocks(selection.getRegionSelector().getRegion(), targetBedrock, new BaseBlock(165));
editSession.flushQueue();
p.sendMessage(WarShipFactory.S_PREFIX + "In Region " + rgID + " wurden " + tnt + " Blöcke Obsidian zu TNT und " + slime + " Blöcke Bedrock zu Slime replacet!");
} catch(Exception ex) { ex.printStackTrace(); }
}
}
}
return false;
}
@Command(name = "bau.info", inGameOnly = true)
public void onInfo(CommandArgs args) {
final Player p = args.getPlayer();
final FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu stehst auf keiner Bauwelt");
return;
}
Bukkit.getScheduler().runTaskAsynchronously(WarShipFactory.getInstance(), new Runnable() {
public void run() {
p.sendMessage(WarShipFactory.S_PREFIX + "§3--- §6Informationen §3---");
StringBuilder members = new StringBuilder();
String ownaz = UUIDFetcher.getName(fw.getOwner());
for (WorldPlayer wp : fw.getMembers().getAll().values()) {
members.append(UUIDFetcher.getName(wp.getUuid()) + ", ");
}
String membas = "";
if (!members.toString().isEmpty()) {
membas = members.toString().trim().substring(0, members.toString().trim().length() - 1);
}
membas = membas.isEmpty() ? "Keine" : membas;
p.sendMessage("§8Registrierungsnummer: §6" + WarShipFactory.getInstance().factoryWorlds.getID(fw));
p.sendMessage("§8Adresse: §6" + fw.getWorldAddress());
p.sendMessage("§8Besitzer: §6" + ownaz);
p.sendMessage("§8Mitglieder: §6" + membas);
}
});
}
@Command(name = "bau.tntdmg", inGameOnly = true)
public void onTntdmg(CommandArgs args) {
Player p = args.getPlayer();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
return;
}
fw.setTntDamage(!fw.isTntDamage());
if (fw.isTntDamage()) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aTNT Schaden erlaubt.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cTNT Schaden verboten.");
}
}
private void pasteSchematic(Player player, File schematic, Vector position) {
int count = 0;
World world = player.getWorld();
for(ProtectedRegion rg:WarShipFactory.getWorldGuard().getRegionManager(world).getApplicableRegions(player.getLocation())) {
count++;
if(count != 0) {
EditSession session = WarShipFactory.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(world), Integer.MAX_VALUE);
try {
CuboidClipboard format = MCEditSchematicFormat.getFormat(schematic).load(schematic);
format.paste(session, position, false);
} catch (Exception ex) {
player.sendMessage(ex.getMessage());
ex.printStackTrace();
}
}
}
}
public boolean del(File dir){
if (dir.isDirectory()){
String[] entries = dir.list();
for (int x=0;x<entries.length;x++){
File aktFile = new File(dir.getPath(),entries[x]);
del(aktFile);
}
if (dir.delete())
return true;
else
return false;
}
else{
if (dir.delete())
return true;
else
return false;
}
}
}

Datei anzeigen

@ -0,0 +1,125 @@
package de.quantumnanox.warshipfactory.commands;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class CommandGamemode extends BukkitCommand {
private static final List<String> GAMEMODE_NAMES = ImmutableList.of("adventure", "creative", "survival",
"spectator");
public CommandGamemode() {
super("gm");
this.description = "Ändert den Spielmodus eines Spielers";
this.usageMessage = "/gm <mode> [player]";
}
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
// SEAGIANTS
if (sender instanceof Player) {
Player p = (Player) sender;
if (p.hasPermission("bukkit.command.gamemode") == false) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage("Du befindest dich auf keiner Bauwelt!");
return false;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp == null && !fw.getOwner().equals(p.getUniqueId())) {
p.sendMessage("Du bist kein Mitglied dieser Welt!");
return false;
}
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canChangeGamemode == false) {
p.sendMessage("Du darfst deinen Spielmodus nicht ändern!");
return false;
}
}
}
}
// END
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Benutzung: " + this.usageMessage);
return false;
}
String modeArg = args[0];
String playerArg = sender.getName();
if (args.length == 2 && sender.hasPermission("bukkit.command.gamemode")) {
playerArg = args[1];
}
Player player = Bukkit.getPlayerExact(playerArg);
if (player != null) {
int value = -1;
try {
value = Integer.parseInt(modeArg);
} catch (NumberFormatException localNumberFormatException) {
}
GameMode mode = GameMode.getByValue(value);
if (mode == null) {
if ((modeArg.equalsIgnoreCase("creative")) || (modeArg.equalsIgnoreCase("c")))
mode = GameMode.CREATIVE;
else if ((modeArg.equalsIgnoreCase("adventure")) || (modeArg.equalsIgnoreCase("a")))
mode = GameMode.ADVENTURE;
else if ((modeArg.equalsIgnoreCase("spectator")) || (modeArg.equalsIgnoreCase("sp")))
mode = GameMode.SPECTATOR;
else {
mode = GameMode.SURVIVAL;
}
}
if (mode != player.getGameMode()) {
player.setGameMode(mode);
if (mode != player.getGameMode()) {
sender.sendMessage("Spielmodus setzen für " + player.getName() + " fehlgeschlagen!");
} else if (player == sender)
Command.broadcastCommandMessage(sender, "Setzte eigenen Spielmodus zu " + mode.toString());
else
Command.broadcastCommandMessage(sender,
"Setzte " + player.getName() + "'s Spielmodus zu " + mode.toString());
} else {
sender.sendMessage(player.getName() + " ist bereits im " + mode.toString() + " mode");
}
} else {
sender.sendMessage("Spieler konnte nicht gefunden werden: " + playerArg);
}
return true;
}
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if (args.length == 1)
return ((List) StringUtil.copyPartialMatches(args[0], GAMEMODE_NAMES,
new ArrayList(GAMEMODE_NAMES.size())));
if (args.length == 2) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -0,0 +1,569 @@
package de.quantumnanox.warshipfactory.commands;
import de.pro_crafting.commandframework.CommandArgs;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.UUIDFetcher;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
import org.bukkit.*;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import sun.security.jca.GetInstance;
import java.util.HashMap;
import java.util.UUID;
public class CommandGui implements Listener {
@EventHandler
public void onPlayerClickInventory(InventoryClickEvent e) {
if (e.getInventory().getTitle().equals("§bBau Abteilungen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarShip §aTestGeländer 1")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -943 122 149");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarShip TestGelände 1 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarShip §aTestGelände 2")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -1200 122 149");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarShip TestGelände 1 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarGear §aTestGelände 5")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -1332 122 -53");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarGear TestGelände 5 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarGear §aTestGelände 6")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -1220 122 -53");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarGear TestGelände 6 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarGear §aTestGelände 7")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -1108 122 -53");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarGear TestGelände 7 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWarGear §aTestGelände 8")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -996 122 -53");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu WarGear TestGelände 8 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bMiniWarGear §aTestGelände 1")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -907 122 -29");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu MiniWarGear TestGelände 1 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bMiniWarGear §aTestGelände 2")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -841 122 -29");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu MiniWarGear TestGelände 2 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bMiniWarGear §aTestGelände 7")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -907 122 -120");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu MiniWarGear TestGelände 7 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bMiniWarGear §aTestGelände 8")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -841 122 -120");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu MiniWarGear TestGelände 8 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 1")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -674 122 -45");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 1 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 2")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -487 122 -45");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 2 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 3")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -302 122 -45");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 3 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 4")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -115 122 -45");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 4 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 5")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -115 122 201");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 5 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 6")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -302 122 201");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 6 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 7")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -487 122 201");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 7 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bAirShip §aTestGelände 8")) {
//code
Player p = (Player) e.getWhoClicked();
p.performCommand("minecraft:tp -674 122 201");
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du wurdest zu AirShip TestGelände 8 Teleportiert");
e.getView().close();
e.setCancelled(true);
}
}
}
}
if (e.getInventory().getTitle().equals("§bWelten Optionen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§aTNT Schaden")) {
//code
Player p = (Player) e.getWhoClicked();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
e.setCancelled(true);
return;
}
fw.setTntDamage(!fw.isTntDamage());
if (fw.isTntDamage()) {
p.sendMessage(WarShipFactory.S_PREFIX + "§aAuf deiner Welt ist jetzt TNT Schaden erlaubt.");
} else {
p.sendMessage(WarShipFactory.S_PREFIX + "§cAuf deiner Welt ist jetzt TNT Schaden verboten.");
}
e.getView().close();
Player p1 = (Player) e.getWhoClicked();
FactoryWorld fw1 = WarShipFactory.getInstance().getWorldFromOwner(p1.getUniqueId());
Inventory inv2 = Bukkit.createInventory(null, 18, "§bWelten Optionen");
ItemStack tnt = new ItemStack(Material.TNT);
ItemMeta meta = tnt.getItemMeta();
meta = tnt.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aTNT Schaden");
tnt.setItemMeta(meta);
inv2.addItem(tnt);
ItemStack back = new ItemStack(Material.SLIME_BALL);
meta = back.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bZurück");
back.setItemMeta(meta);
inv2.setItem(4, back);
e.setCancelled(true);
ItemStack fire = new ItemStack(Material.LAVA_BUCKET);
meta = fire.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aFeuer Schaden");
fire.setItemMeta(meta);
inv2.setItem(8, fire);
p.closeInventory();
p.openInventory(inv2);
e.setCancelled(true);
if (fw1.isTntDamage()) {
ItemStack tntst = new ItemStack(351, 1, (short) 10);
meta = tntst.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §2An");
tntst.setItemMeta(meta);
inv2.setItem(9, tntst);
p.closeInventory();
p.openInventory(inv2);
} else {
ItemStack tntst1 = new ItemStack(351, 1, (short) 8);
meta = tntst1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §4Aus");
tntst1.setItemMeta(meta);
inv2.setItem(9, tntst1);
p.closeInventory();
p.openInventory(inv2);
}
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§aFeuer Schaden")) {
//code
Player p = (Player) e.getWhoClicked();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
e.setCancelled(true);
return;
}
p.sendMessage(WarShipFactory.S_PREFIX + "§7Kommt Bald");
e.getView().close();
e.setCancelled(true);
return;
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§eStatus §2An")) {
//code
Player p = (Player) e.getWhoClicked();
p.sendMessage(WarShipFactory.S_PREFIX + "§4Du darfst das nicht");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§eStatus §4Aus")) {
//code
Player p = (Player) e.getWhoClicked();
p.sendMessage(WarShipFactory.S_PREFIX + "§4Das darfst du nicht");
e.getView().close();
e.setCancelled(true);
}
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bZurück")) {
//code
Player p = (Player) e.getWhoClicked();
e.getView().close();
Inventory inv = Bukkit.createInventory(null, 9, "§aBau Optionen");
ItemStack bau = new ItemStack(Material.COMPASS);
ItemMeta meta = bau.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bBau Abteilungen");
bau.setItemMeta(meta);
inv.addItem(bau);
ItemStack optionen = new ItemStack(Material.ENCHANTED_BOOK);
meta = optionen.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWelten Optionen");
optionen.setItemMeta(meta);
inv.setItem(8, optionen);
ItemStack spieler = new ItemStack(Material.REDSTONE_BLOCK);
meta = spieler.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bSpieler Optionen");
spieler.setItemMeta(meta);
inv.setItem(4, spieler);
p.openInventory(inv);
e.setCancelled(true);
}
}
}
}
if (e.getInventory().getTitle().equals("§aBau Optionen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bBau Abteilungen")) {
//code
Player p = (Player) e.getWhoClicked();
Inventory inv1 = Bukkit.createInventory(null, 36, "§bBau Abteilungen");
ItemStack warship1 = new ItemStack(Material.WATER_BUCKET);
ItemMeta meta = warship1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarShip §aTestGelände 1");
warship1.setItemMeta(meta);
inv1.addItem(warship1);
ItemStack warship2 = new ItemStack(Material.WATER_BUCKET);
meta = warship2.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarShip §aTestGelände 2");
warship2.setItemMeta(meta);
inv1.setItem(1, warship2);
ItemStack wargear1 = new ItemStack(Material.REDSTONE_BLOCK);
meta = wargear1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarGear §aTestGelände 5");
wargear1.setItemMeta(meta);
inv1.setItem(9, wargear1);
ItemStack wargear2 = new ItemStack(Material.REDSTONE_BLOCK);
meta = wargear2.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarGear §aTestGelände 6");
wargear2.setItemMeta(meta);
inv1.setItem(10, wargear2);
ItemStack wargear3 = new ItemStack(Material.REDSTONE_BLOCK);
meta = wargear3.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarGear §aTestGelände 7");
wargear3.setItemMeta(meta);
inv1.setItem(11, wargear3);
ItemStack wargear4 = new ItemStack(Material.REDSTONE_BLOCK);
meta = wargear4.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bWarGear §aTestGelände 8");
wargear4.setItemMeta(meta);
inv1.setItem(12, wargear4);
ItemStack miniwargear1 = new ItemStack(Material.REDSTONE);
meta = miniwargear1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bMiniWarGear §aTestGelände 1");
miniwargear1.setItemMeta(meta);
inv1.setItem(18, miniwargear1);
ItemStack miniwargear2 = new ItemStack(Material.REDSTONE);
meta = miniwargear2.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bMiniWarGear §aTestGelände 2");
miniwargear2.setItemMeta(meta);
inv1.setItem(19, miniwargear2);
ItemStack miniwargear3 = new ItemStack(Material.REDSTONE);
meta = miniwargear3.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bMiniWarGear §aTestGelände 7");
miniwargear3.setItemMeta(meta);
inv1.setItem(20, miniwargear3);
ItemStack miniwargear4 = new ItemStack(Material.REDSTONE);
meta = miniwargear4.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bMiniWarGear §aTestGelände 8");
miniwargear4.setItemMeta(meta);
inv1.setItem(21, miniwargear4);
ItemStack airship1 = new ItemStack(Material.ELYTRA);
meta = airship1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 1");
airship1.setItemMeta(meta);
inv1.setItem(27, airship1);
ItemStack airship2 = new ItemStack(Material.ELYTRA);
meta = airship2.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 2");
airship2.setItemMeta(meta);
inv1.setItem(28, airship2);
ItemStack airship3 = new ItemStack(Material.ELYTRA);
meta = airship3.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 3");
airship3.setItemMeta(meta);
inv1.setItem(29, airship3);
ItemStack airship4 = new ItemStack(Material.ELYTRA);
meta = airship4.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 4");
airship4.setItemMeta(meta);
inv1.setItem(30, airship4);
ItemStack airship5 = new ItemStack(Material.ELYTRA);
meta = airship5.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 5");
airship5.setItemMeta(meta);
inv1.setItem(31, airship5);
ItemStack airship6 = new ItemStack(Material.ELYTRA);
meta = airship6.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 6");
airship6.setItemMeta(meta);
inv1.setItem(32, airship6);
ItemStack airship7 = new ItemStack(Material.ELYTRA);
meta = airship7.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 7");
airship7.setItemMeta(meta);
inv1.setItem(33, airship7);
ItemStack airship8 = new ItemStack(Material.ELYTRA);
meta = airship8.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bAirShip §aTestGelände 8");
airship8.setItemMeta(meta);
inv1.setItem(34, airship8);
p.openInventory(inv1);
}
}
}
}
if (e.getInventory().getTitle().equals("§aBau Optionen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bWelten Optionen")) {
//code
Player p = (Player) e.getWhoClicked();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
Inventory inv2 = Bukkit.createInventory(null, 18, "§bWelten Optionen");
ItemStack tnt = new ItemStack(Material.TNT);
ItemMeta meta = tnt.getItemMeta();
meta = tnt.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aTNT Schaden");
tnt.setItemMeta(meta);
inv2.addItem(tnt);
ItemStack back = new ItemStack(Material.SLIME_BALL);
meta = back.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bZurück");
back.setItemMeta(meta);
inv2.setItem(4, back);
e.setCancelled(true);
ItemStack fire = new ItemStack(Material.LAVA_BUCKET);
meta = fire.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aFeuer Schaden");
fire.setItemMeta(meta);
inv2.setItem(8, fire);
p.openInventory(inv2);
e.setCancelled(true);
if (fw.isTntDamage()) {
ItemStack tntst = new ItemStack(351, 1, (short) 10);
meta = tntst.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §2An");
tntst.setItemMeta(meta);
inv2.setItem(9, tntst);
p.closeInventory();
p.openInventory(inv2);
} else {
ItemStack tntst1 = new ItemStack(351, 1, (short) 8);
meta = tntst1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §4Aus");
tntst1.setItemMeta(meta);
inv2.setItem(9, tntst1);
p.closeInventory();
p.openInventory(inv2);
}
}
}
}
}
if (e.getInventory().getTitle().equals("§aBau Optionen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.RED + "§bSpieler Optionen")) {
//code
Player player = (Player) e.getWhoClicked();
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(player.getUniqueId());
Inventory inv = Bukkit.createInventory(null, 54, "§bSpieler Optionen");
{
e.setCancelled(true);
inv.clear();
int slot = 0;
for (Player p : Bukkit.getWorld(player.getWorld().getName()).getPlayers()) {
inv.setItem(slot, getSkull(p.getName()));
slot++;
}
player.openInventory(inv);
}
}
}
}
}
if (e.getInventory().getTitle().equals("§bSpieler Optionen")) {
if (e.getCurrentItem().getItemMeta() != null) {
if (e.getCurrentItem().getItemMeta().getDisplayName() != null) {
Player player = (Player) e.getWhoClicked();
if (e.getCurrentItem() != null) {
Material material = e.getCurrentItem().getType();
if (material == Material.SKULL_ITEM) {
SkullMeta skullMeta = (SkullMeta) getSkull(material.getData().getCanonicalName()).getItemMeta();
SkullTeleport(player, e.getCurrentItem());
}
}
}
}
}
}
public ItemStack getSkull(String name) {
ItemStack skull = new ItemStack(397, 1, (short) 3);
SkullMeta skullmeta = (SkullMeta) skull.getItemMeta();
skullmeta.setDisplayName(name);
skullmeta.setOwner(name);
skull.setItemMeta(skullmeta);
return skull;
}
public void onInventoryClick(InventoryClickEvent event, ItemStack item) {
if (event.getInventory().getName().contains("§bSpieler Optionen")) {
event.setCancelled(true);
Player player = (Player) event.getWhoClicked();
SkullMeta skullmeta = (SkullMeta) item.getItemMeta();
Player target = Bukkit.getPlayer(skullmeta.getDisplayName());
{
if (event.getSlotType() == InventoryType.SlotType.CONTAINER) {
SkullTeleport(player, event.getCurrentItem());
}
}
}
}
public void SkullTeleport(Player player, ItemStack item) {
if (item.getType() != Material.AIR && item != null) {
SkullMeta skullmeta = (SkullMeta) item.getItemMeta();
if (skullmeta.getDisplayName() != null) {
if (Bukkit.getPlayer(skullmeta.getDisplayName()) != null) {
Player target = Bukkit.getPlayer(skullmeta.getDisplayName());
player.openInventory(skullOwnerInventory(target));
}
}
}
}
private Inventory skullOwnerInventory(Player p) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldFromOwner(p.getUniqueId());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§cDu hast keine Welt");
}
ItemStack skull = new ItemStack(Material.SKULL_ITEM);
ItemMeta meta = skull.getItemMeta();
Inventory inv2 = Bukkit.createInventory(null, 18, p.getDisplayName());
meta = skull.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aSpieler hinzufügen");
skull.setItemMeta(meta);
inv2.addItem(skull);
ItemStack togglewe = new ItemStack(Material.WOOD_AXE);
meta = togglewe.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aToggle Worldedit");
togglewe.setItemMeta(meta);
inv2.setItem(1, togglewe);
ItemStack back = new ItemStack(Material.SLIME_BALL);
meta = back.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§bZurück");
back.setItemMeta(meta);
inv2.setItem(4, back);
ItemStack fire = new ItemStack(Material.LAVA_BUCKET);
meta = fire.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§aFeuer Schaden");
fire.setItemMeta(meta);
inv2.setItem(8, fire);
p.openInventory(inv2);
if (fw.isTntDamage()){
ItemStack tntst = new ItemStack(351, 1, (short) 10);
meta = tntst.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §2An");
tntst.setItemMeta(meta);
inv2.setItem(9, tntst);
p.closeInventory();
p.openInventory(inv2);
} else {
ItemStack tntst1 = new ItemStack(351, 1, (short) 8);
meta = tntst1.getItemMeta();
meta.setDisplayName(ChatColor.RED + "§eStatus §4Aus");
tntst1.setItemMeta(meta);
inv2.setItem(9, tntst1);
p.closeInventory();
p.openInventory(inv2);
}
return inv2;
}
}

Datei anzeigen

@ -0,0 +1,180 @@
/*** Eclipse Class Decompiler plugin, copyright (c) 2016 Chen Chao (cnfree2000@hotmail.com) ***/
package de.quantumnanox.warshipfactory.commands;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.google.common.collect.ImmutableList;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class CommandTeleport extends BukkitCommand {
public CommandTeleport() {
super("tp");
this.description = "Teleports the given player (or yourself) to another player or coordinates";
this.usageMessage = "/tp [player] <target> and/or <x> <y> <z>";
}
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
if ((args.length < 1) || (args.length > 4)) {
sender.sendMessage(ChatColor.RED + "Usage: " + this.usageMessage);
return false;
}
// SEAGIANTS
if (sender instanceof Player) {
Player p = (Player) sender;
if (p.hasPermission("bukkit.command.teleport") == false) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage("Du befindest dich auf keiner Bauwelt!");
return false;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp == null && !fw.getOwner().equals(p.getUniqueId())) {
p.sendMessage("Du bist kein Mitglied dieser Welt!");
return false;
}
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canTeleport == false) {
p.sendMessage("Du darfst dich auf dieser Welt nicht teleportieren!");
return false;
}
}
}
}
// END
Player player = Bukkit.getPlayerExact(args[0]);
if (player == null && args.length != 3) {
sender.sendMessage("Player not found: " + args[0]);
return true;
}
if (args.length == 1 || args.length == 3) {
if (sender instanceof Player) {
player = (Player) sender;
}
}
if (args.length < 3) {
Player target = Bukkit.getPlayerExact(args[(args.length - 1)]);
if (target == null) {
sender.sendMessage("Can't find player " + args[(args.length - 1)] + ". No tp.");
return true;
}
// SEAGIANTS
if (!sender.hasPermission("bukkit.command.teleport")) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(player.getWorld().getName());
if (fw == null) {
sender.sendMessage("Der Spieler befindet sich auf keiner Bauwelt.");
return false;
}
FactoryWorld fwt = WarShipFactory.getInstance().getWorldByAddress(target.getWorld().getName());
if (fwt == null) {
sender.sendMessage("Der Zielspieler befindet sich auf keiner Bauwelt.");
return false;
}
if (fw.getWrapped().getUID().equals(fwt.getWrapped().getUID()) == false) {
sender.sendMessage("Die Spieler sind nicht auf der selben Bauwelt.");
return false;
}
if (sender instanceof Player) {
Player p = (Player) sender;
FactoryWorld fwp = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fwp == null) {
p.sendMessage("Du bist auf keiner Bauwelt");
return false;
}
if (fwt.getWrapped().getUID().equals(fwp.getWrapped().getUID()) == false) {
p.sendMessage("Das Ziel befindet sich nicht auf deiner Welt");
return false;
}
}
}
// END
player.teleport(target, PlayerTeleportEvent.TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender,
"Teleported " + player.getDisplayName() + " to " + target.getDisplayName());
} else if (player.getWorld() != null) {
Location playerLocation = player.getLocation();
double x = getCoordinate(sender, playerLocation.getX(), args[(args.length - 3)]);
double y = getCoordinate(sender, playerLocation.getY(), args[(args.length - 2)], 0, 0);
double z = getCoordinate(sender, playerLocation.getZ(), args[(args.length - 1)]);
if ((x == -30000001.0D) || (y == -30000001.0D) || (z == -30000001.0D)) {
sender.sendMessage("Please provide a valid location!");
return true;
}
playerLocation.setX(x);
playerLocation.setY(y);
playerLocation.setZ(z);
player.teleport(playerLocation, PlayerTeleportEvent.TeleportCause.COMMAND);
Command.broadcastCommandMessage(sender, String.format("Teleported %s to %.2f, %.2f, %.2f",
new Object[] { player.getDisplayName(), Double.valueOf(x), Double.valueOf(y), Double.valueOf(z) }));
}
return true;
}
private double getCoordinate(CommandSender sender, double current, String input) {
return getCoordinate(sender, current, input, -30000000, 30000000);
}
private double getCoordinate(CommandSender sender, double current, String input, int min, int max) {
boolean relative = input.startsWith("~");
double result = (relative) ? current : 0.0D;
if ((!(relative)) || (input.length() > 1)) {
boolean exact = input.contains(".");
if (relative)
input = input.substring(1);
double testResult = getCoordinate(sender,current, input);
if (testResult == -30000001.0D) {
return -30000001.0D;
}
result += testResult;
if ((!(exact)) && (!(relative)))
result += 0.5D;
}
if ((min != 0) || (max != 0)) {
if (result < min) {
result = -30000001.0D;
}
if (result > max) {
result = -30000001.0D;
}
}
return result;
}
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
if ((args.length == 1) || (args.length == 2)) {
return super.tabComplete(sender, alias, args);
}
return ImmutableList.of();
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package de.quantumnanox.warshipfactory.commands;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import de.quantumnanox.warshipfactory.content.WorldPlayer;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class CommandTestBlock extends Commandtestblock1 {
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
// SEAGIANTS
if (sender instanceof Player) {
Player p = (Player) sender;
if (p.hasPermission("nnx.user") == false) {
FactoryWorld fw = WarShipFactory.getInstance().getWorldByAddress(p.getWorld().getName());
if (fw == null) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du befindest dich auf keiner Bauwelt!");
return false;
}
WorldPlayer wp = fw.getMember(p.getUniqueId());
if (wp == null && !fw.getOwner().equals(p.getUniqueId())) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du bist kein Mitglied dieser Welt!");
return false;
}
if (!fw.getOwner().equals(p.getUniqueId())) {
if (wp.canTestBlock == false) {
p.sendMessage(WarShipFactory.S_PREFIX + "§7Du darfst keinen TestBlock erneuern!");
return false;
}
}
}
}
return false;
}
}

Datei anzeigen

@ -0,0 +1,201 @@
package de.quantumnanox.warshipfactory.commands;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.boydti.fawe.jnbt.anvil.MCAFilterCounter;
import com.boydti.fawe.jnbt.anvil.MCAQueue;
import com.boydti.fawe.object.number.MutableLong;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.schematic.MCEditSchematicFormat;
import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class Commandtestblock1 implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) {
Player p = (Player) sender;
try {
if(p.hasPermission("nnx.user")) {
//args länge 0
if(args.length == 0) {
p.sendMessage("§4Verwende /bau help");
return false;
}
//args länge 1
if(args.length == 1) {
//Testblock
if(args[0].equalsIgnoreCase("testblock")) {
Location playerLocation = p.getLocation();
World playerWorld = p.getWorld();
@SuppressWarnings("unused")
int count = 0;
for(ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(playerWorld).getApplicableRegions(playerLocation)) {
count++;
String rgID = rg.getId().toString();
p.sendMessage(rgID);
Vector position = new Vector(Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.X")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Y")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Z")));
File file = new File(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".schematic.testblock"));
pasteSchematic(p, file, position);
p.sendMessage(WarShipFactory.S_PREFIX + "Testblock erneuert!");
}
return false;
}
if(args[0].equalsIgnoreCase("reset")) {
Location playerLocation = p.getLocation();
World playerWorld = p.getWorld();
@SuppressWarnings("unused")
int count = 0;
for(ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(playerWorld).getApplicableRegions(playerLocation)) {
count++;
String rgID = rg.getId().toString();
Vector position = new Vector(Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.X")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Y")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".position.Z")));
File file = new File(WarShipFactory.getPlugin().getRegionData.getString("regions." + rgID + ".schematic.reset"));
pasteSchematic(p, file, position);
p.sendMessage(WarShipFactory.S_PREFIX + "Region " + rgID + " wurde resettet!");
}
return false;
}
if(args[0].equalsIgnoreCase("resetall")) {
Location playerLocation = p.getLocation();
World playerWorld = p.getWorld();
@SuppressWarnings("unused")
int count = 0;
for(@SuppressWarnings("unused") ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(playerWorld).getApplicableRegions(playerLocation)) {
count++;
Vector position = new Vector(Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("schematic.resetall.position.X")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("schematic.resetall.position.Y")), Integer.parseInt(WarShipFactory.getPlugin().getRegionData.getString("schematic.resetall.position.Z")));
File file = new File(WarShipFactory.getPlugin().getRegionData.getString("schematic.resetall.schematic"));
pasteSchematic(p, file, position);
p.sendMessage(WarShipFactory.S_PREFIX + "Alle Regionen wurden resettet!");
}
return false;
}
if(args[0].equalsIgnoreCase("replace")) {
World world = p.getWorld();
int count = 0;
for(ProtectedRegion rg : WarShipFactory.getPlugin().getWorldGuard().getRegionManager(world).getApplicableRegions(p.getLocation())) {
count++;
if(count != 0) {
String gsID = rg.getId();
String worldName = p.getWorld().getName();
File root = new File(worldName + File.separator + "region");
MCAQueue queue = new MCAQueue(worldName, root, true);
@SuppressWarnings("unused")
MCAFilterCounter counter = queue.filterWorld(new MCAFilterCounter() {
@Override
public void applyBlock(int x, int y, int z, BaseBlock block, MutableLong ignore) {
if(block.getId() == 49) { // Change the id if it's 5
block.setId(46);
}
if(block.getId() == 7) {
block.setId(165);
}
}
});
p.sendMessage(WarShipFactory.S_PREFIX + "In Region " + gsID + " wurde Obsidian und Bedrock replacet!");
}
}
return false;
}
}
} else
p.sendMessage("");
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
private void pasteSchematic(Player player, File schematic, Vector position) {
int count = 0;
World world = player.getWorld();
for(ProtectedRegion rg:WarShipFactory.getWorldGuard().getRegionManager(world).getApplicableRegions(player.getLocation())) {
count++;
if(count != 0) {
EditSession session = WarShipFactory.getWorldEdit().getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(world), Integer.MAX_VALUE);
try {
CuboidClipboard format = MCEditSchematicFormat.getFormat(schematic).load(schematic);
format.paste(session, position, false);
} catch (Exception ex) {
player.sendMessage(ex.getMessage());
ex.printStackTrace();
}
}
}
}
/*
private void pasteSchem(File schematic, Player player, Vector position, boolean allowUndo, boolean noAir) {
com.sk89q.worldedit.world.World weWorld = new BukkitWorld(player.getWorld());
try {
EditSession editSession = ClipboardFormat.findByFile(schematic).load(schematic).paste(weWorld, position, allowUndo, !noAir, (Transform) null);
editSession.flushQueue();
} catch (IOException e) {
e.printStackTrace();
}
}*/
}

Datei anzeigen

@ -0,0 +1,76 @@
package de.quantumnanox.warshipfactory.config;
import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.WorldCreator;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class Config {
private File file;
public FileConfiguration cfg;
public String backupDir;
public String regionDir;
public Location spawn;
public Location wargear1mini;
public Location pasteloc;
public Config() {
this.file = new File("plugins/WarShipFactory/config.yml");
this.cfg = YamlConfiguration.loadConfiguration(this.file);
}
public void initConfig() {
this.cfg.options().copyDefaults(true);
cfg.options().header("Locations are in format: world/x/y/z/yaw/pitch");
this.cfg.addDefault("WorldSource.dir", "dirHere");
this.cfg.addDefault("RegionSource.dir", "dirHere");
cfg.addDefault("Location.spawn", "world/0/64/0/90/0");
cfg.addDefault("Coords.loc.x", 0);
cfg.addDefault("Coords.loc.y", 0);
cfg.addDefault("Coords.loc.z", 0);
cfg.addDefault("Coords.wargear1mini.loc.x", -943);
cfg.addDefault("Coords.wargear1mini.loc.y", 122);
cfg.addDefault("Coords.wargear1mini.loc.z", 149);
cfg.addDefault("Lobby.name", "Lobby_1");
try {
this.cfg.save(this.file);
} catch (IOException e) {
e.printStackTrace();
}
backupDir = cfg.getString("WorldSource.dir");
regionDir = cfg.getString("RegionSource.dir");
spawn = toLocation(cfg.getString("Location.spawn"));
pasteloc = new Location(null, cfg.getDouble("Coords.loc.x"), cfg.getDouble("Coords.loc.y"), cfg.getDouble("Coords.loc.z"));
wargear1mini = new Location(pasteloc.getWorld(), cfg.getDouble("Coords.wargear1mini.loc.x"), cfg.getDouble("Coords.wargear1mini.loc.y"), cfg.getDouble("Coords.wargear1mini.loc.z"));
}
public Location toLocation(String configString) {
String[] splitted = configString.split("/");
String wName = splitted[0];
double x = Double.parseDouble(splitted[1]);
double y = Double.parseDouble(splitted[2]);
double z = Double.parseDouble(splitted[3]);
float yaw = Float.parseFloat(splitted[4]);
float pitch = Float.parseFloat(splitted[5]);
if(Bukkit.getWorld(wName) == null)
Bukkit.createWorld(new WorldCreator(wName));
return new Location(Bukkit.getWorld(wName), x, y, z, yaw, pitch);
}
public void save() {
try {
this.cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
}

Datei anzeigen

@ -0,0 +1,162 @@
package de.quantumnanox.warshipfactory.content;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.GameMode;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import de.quantumnanox.warshipfactory.main.CobixTagFormatSupported;
import de.quantumnanox.warshipfactory.main.Registry;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
import lombok.Getter;
import lombok.Setter;
import net.thecobix.tag.TagCompound;
public class FactoryWorld extends CobixTagFormatSupported {
private int regId;
@Getter
private World wrapped;
@Getter
private Registry<WorldPlayer> members = new Registry<>(WorldPlayer.class, "members");
@Getter
private String worldAddress;
@Getter
private UUID owner;
@Getter
private boolean loading;
@Getter
@Setter
private boolean tntDamage;
private BukkitTask task;
public FactoryWorld() {
task = Bukkit.getScheduler().runTaskTimer(WarShipFactory.getInstance(), new LagDetectorRunnable(this), 20, 20);
}
public FactoryWorld(UUID ownaz) {
this.owner = ownaz;
this.worldAddress = Bukkit.getPlayer(ownaz).getUniqueId().toString();
task = Bukkit.getScheduler().runTaskTimer(WarShipFactory.getInstance(), new LagDetectorRunnable(this), 20, 20);
}
@Override
public TagCompound save() {
TagCompound out = new TagCompound(regId + "");
out.put(members.save());
out.putString("worldAddress", worldAddress);
out.putString("owner", owner.toString());
out.putShort("tntdmg", (short) (tntDamage ? 1 : 0));
return out;
}
@Override
public void load(TagCompound tc) {
members.load(tc.getTagCompound("members"));
worldAddress = tc.getTagString("worldAddress").getValue();
owner = UUID.fromString(tc.getTagString("owner").getValue());
tntDamage = tc.getTagShort("tntdmg").getValue() == 1 ? true : false;
}
public void loadWorld() throws IOException {
loading = true;
File world = new File("plugins/WarShipFactory/worlds/" + worldAddress);
File region = new File("plugins/WorldGuard/worlds/" + worldAddress);
if (region.exists() && region.isDirectory()) {
} else {
FileUtils.copyDirectory(new File(WarShipFactory.getInstance().config.regionDir), new File("plugins/WorldGuard/worlds/" + worldAddress));
}
if (world.exists() && world.isDirectory()) {
FileUtils.moveDirectory(world, new File(worldAddress));
wrapped = Bukkit.createWorld(new WorldCreator(worldAddress));
} else {
FileUtils.copyDirectory(new File(WarShipFactory.getInstance().config.backupDir), new File(worldAddress));
wrapped = Bukkit.createWorld(new WorldCreator(worldAddress));
}
loading = false;
}
public void unloadWorld() {
wrapped.save();
for (final WorldPlayer wp : members.getAll().values()) {
if (wp.getPlayer() != null) {
if (wp.getPlayer().getWorld().getUID().equals(wrapped.getUID())) {
wp.getPlayer().sendMessage(WarShipFactory.S_PREFIX + "§cDie Welt wurde aus dem Arbeitsspeicher gelöscht...");
wp.getPlayer().teleport(WarShipFactory.getInstance().config.spawn);
Bukkit.getScheduler().scheduleSyncDelayedTask(WarShipFactory.getInstance(), new Runnable() {
public void run() {
wp.getPlayer().setGameMode(GameMode.SURVIVAL);
}
}, 20L);
}
}
}
if (!unloadWorld(worldAddress)) {
WarShipFactory.log("FactoryWorld", "Unable to unload " + worldAddress);
}
wrapped = null;
try {
FileUtils.moveDirectory(new File(worldAddress), new File("plugins/WarShipFactory/worlds/" + worldAddress));
} catch (IOException e) {
e.printStackTrace();
}
}
public WorldPlayer getMember(UUID uuid) {
for (WorldPlayer wp : members.getAll().values()) {
if (wp.getUuid().equals(uuid)) return wp;
}
return null;
}
private boolean isLoaded(String world) {
for (World w : Bukkit.getServer().getWorlds()) {
if (w.getName().equals(world)) {
return true;
}
}
return false;
}
private boolean unloadWorld(String world) {
if (isLoaded(world)) {
World w = Bukkit.getWorld(world);
for (Player p : w.getPlayers()) {
p.teleport(WarShipFactory.getInstance().config.spawn);
}
for (Chunk c : w.getLoadedChunks()) {
c.unload();
}
boolean unload = Bukkit.unloadWorld(w, true);
return unload;
}
return false;
}
public void broadcast(String string) {
for (Player p : wrapped.getPlayers()) {
p.sendMessage(string);
}
}
}

Datei anzeigen

@ -0,0 +1,56 @@
package de.quantumnanox.warshipfactory.content;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
public class LagDetectorRunnable implements Runnable {
private FactoryWorld world;
private boolean timeout;
private long timerstart = 0;
public LagDetectorRunnable(FactoryWorld fw) {
this.world = fw;
}
@Override
public void run() {
if (world.getWrapped() == null) {
return;
}
world.getWrapped().setStorm(false);
world.getWrapped().setThundering(false);
int players = 0;
int other = 0;
for (Entity e : world.getWrapped().getEntities()) {
if (e instanceof Player) {
players++;
} else {
other++;
}
}
if(players == 0 && !timeout) {
timeout = true;
timerstart = System.currentTimeMillis();
} else if(players != 0) {
timeout = false;
}
long diff = System.currentTimeMillis() - timerstart;
if (players == 0 && timeout && diff > 1000*60) {
world.unloadWorld();
return;
}
if (other > 1000) {
for (Entity e : world.getWrapped().getEntities()) {
if (e instanceof Player) {
continue;
}
e.remove();
}
world.broadcast(WarShipFactory.S_PREFIX+"§cLagverursachung erkannt. Es wurden §6"+other+" Entities§c entfernt");
}
}
}

Datei anzeigen

@ -0,0 +1,127 @@
package de.quantumnanox.warshipfactory.content;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.util.UUIDTypeAdapter;
@Deprecated
public class UUIDFetcher {
/**
* Date when name changes were introduced
* @see UUIDFetcher#getUUIDAt(String, long)
*/
public static final long FEBRUARY_2015 = 1422748800000L;
private static Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?at=%d";
private static final String NAME_URL = "https://api.mojang.com/user/profiles/%s/names";
private static Map<String, UUID> uuidCache = new HashMap<String, UUID>();
private static Map<UUID, String> nameCache = new HashMap<UUID, String>();
private static ExecutorService pool = Executors.newCachedThreadPool();
private String name;
private UUID id;
/**
* Fetches the uuid asynchronously and passes it to the consumer
*
* @param name The name
* @param action Do what you want to do with the uuid her
*/
public static void getUUID(String name, Consumer<UUID> action) {
pool.execute(() -> action.accept(getUUID(name)));
}
/**
* Fetches the uuid synchronously and returns it
*
* @param name The name
* @return The uuid
*/
public static UUID getUUID(String name) {
return getUUIDAt(name, System.currentTimeMillis());
}
/**
* Fetches the uuid synchronously for a specified name and time and passes the result to the consumer
*
* @param name The name
* @param timestamp Time when the player had this name in milliseconds
* @param action Do what you want to do with the uuid her
*/
public static void getUUIDAt(String name, long timestamp, Consumer<UUID> action) {
pool.execute(() -> action.accept(getUUIDAt(name, timestamp)));
}
/**
* Fetches the uuid synchronously for a specified name and time
*
* @param name The name
* @param timestamp Time when the player had this name in milliseconds
* @see UUIDFetcher#FEBRUARY_2015
*/
public static UUID getUUIDAt(String name, long timestamp) {
name = name.toLowerCase();
if (uuidCache.containsKey(name)) {
return uuidCache.get(name);
}
try {
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(UUID_URL, name, timestamp/1000)).openConnection();
connection.setReadTimeout(5000);
UUIDFetcher data = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher.class);
uuidCache.put(name, data.id);
nameCache.put(data.id, data.name);
return data.id;
} catch (Exception e) {
}
return null;
}
/**
* Fetches the name asynchronously and passes it to the consumer
*
* @param uuid The uuid
* @param action Do what you want to do with the name her
*/
public static void getName(UUID uuid, Consumer<String> action) {
pool.execute(() -> action.accept(getName(uuid)));
}
/**
* Fetches the name synchronously and returns it
*
* @param uuid The uuid
* @return The name
*/
public static String getName(UUID uuid) {
if (nameCache.containsKey(uuid)) {
return nameCache.get(uuid);
}
try {
HttpURLConnection connection = (HttpURLConnection) new URL(String.format(NAME_URL, UUIDTypeAdapter.fromUUID(uuid))).openConnection();
connection.setReadTimeout(5000);
UUIDFetcher[] nameHistory = gson.fromJson(new BufferedReader(new InputStreamReader(connection.getInputStream())), UUIDFetcher[].class);
UUIDFetcher currentNameData = nameHistory[nameHistory.length - 1];
uuidCache.put(currentNameData.name.toLowerCase(), uuid);
nameCache.put(uuid, currentNameData.name);
return currentNameData.name;
} catch (Exception e) {
}
return null;
}
}

Datei anzeigen

@ -0,0 +1,70 @@
package de.quantumnanox.warshipfactory.content;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import de.quantumnanox.warshipfactory.main.CobixTagFormatSupported;
import de.quantumnanox.warshipfactory.main.WarShipFactory;
import lombok.Getter;
import net.thecobix.tag.TagCompound;
public class WorldPlayer extends CobixTagFormatSupported {
@Getter
private UUID uuid;
public boolean canWorldEdit, canChangeGamemode, canBuild, canTeleport, canTestBlock, canReset, canResetAll, canReplace;
@Getter
private FactoryWorld factoryWorld;
private int regId;
public WorldPlayer() {
//To be created by registries
}
public WorldPlayer(UUID id, FactoryWorld world) {
this.uuid = id;
this.factoryWorld = world;
}
public Player getPlayer() {
return Bukkit.getPlayer(uuid);
}
@Override
public TagCompound save() {
TagCompound tc = new TagCompound(regId+"");
tc.putString("uuid", uuid.toString());
tc.putShort("canWorldEdit", (short) (canWorldEdit ? 1 : 0));
tc.putShort("canTestBlock", (short) (canTestBlock ? 1 : 0));
tc.putShort("canResetAll", (short) (canResetAll ? 1 : 0));
tc.putShort("canReset", (short) (canReset ? 1 : 0));
tc.putShort("canReplace", (short) (canReplace ? 1 : 0));
tc.putShort("canChangeGamemode", (short) (canChangeGamemode ? 1 : 0));
tc.putShort("canBuild", (short) (canBuild ? 1 : 0));
tc.putShort("canTeleport", (short) (canTeleport ? 1 : 0));
tc.putString("factoryWorld", factoryWorld.getWorldAddress());
return tc;
}
@Override
public void load(TagCompound tc) {
uuid = UUID.fromString(tc.getTagString("uuid").getValue());
canBuild = tc.getTagShort("canBuild").getValue() == 1 ? true : false;
canWorldEdit = tc.getTagShort("canWorldEdit").getValue() == 1 ? true : false;
canTestBlock = tc.getTagShort("canTestBlock").getValue() == 1 ? true : false;
canReset = tc.getTagShort("canReset").getValue() == 1 ? true : false;
canReplace = tc.getTagShort("canReplace").getValue() == 1 ? true : false;
canResetAll = tc.getTagShort("canResetAll").getValue() == 1 ? true : false;
canTeleport = tc.getTagShort("canTeleport").getValue() == 1 ? true : false;
canChangeGamemode = tc.getTagShort("canChangeGamemode").getValue() == 1 ? true : false;
Bukkit.getScheduler().runTaskLater(WarShipFactory.getInstance(), new Runnable() {
public void run() {
factoryWorld = WarShipFactory.getInstance().getWorldByAddress(tc.getTagString("factoryWorld").getValue());
}
}, 20L);
}
}

Datei anzeigen

@ -0,0 +1,78 @@
package de.quantumnanox.warshipfactory.main;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
public class BungeeUtil implements PluginMessageListener {
private String[] lastPlayerList = null;
private boolean wait = false;
private boolean lastHasInvitation;
public BungeeUtil()
{
Bukkit.getMessenger().registerIncomingPluginChannel(WarShipFactory.getInstance(), "BungeeCord", this);
}
public void sendToServer(Player p, String server) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(server);
p.sendPluginMessage(WarShipFactory.getInstance(), "BungeeCord", out.toByteArray());
}
public void broadcast(String msg, Player from) {
sendMessage(msg, from);
}
public void sendMessage(String msg, Player from) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("BroadcastWS");
out.writeUTF("channelMessage");
out.writeUTF(Bukkit.getServerName());
out.writeUTF(from.getUniqueId().toString());
out.writeUTF(msg);
from.sendPluginMessage(WarShipFactory.getInstance(), "BungeeCord", out.toByteArray());
}
public String[] getPlayers(String server) {
this.wait = true;
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("PlayerList");
out.writeUTF(server);
Bukkit.getServer().sendPluginMessage(WarShipFactory.getInstance(), "BungeeCord", out.toByteArray());
while(this.wait) {
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{
}
}
return this.lastPlayerList;
}
@Override
public void onPluginMessageReceived(String channel, Player p, byte[] message)
{
if(!channel.equals("BungeeCord")) {
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(message);
String subchannel = in.readUTF();
if(subchannel.equals("PlayerList")) {
String server = in.readUTF();
String msg = in.readUTF();
System.out.println(msg);
this.lastPlayerList = msg.split(", ");
this.wait = false;
}
}
}

Datei anzeigen

@ -0,0 +1,10 @@
package de.quantumnanox.warshipfactory.main;
import net.thecobix.tag.TagCompound;
public abstract class CobixTagFormatSupported {
public abstract TagCompound save();
public abstract void load(TagCompound tc);
}

Datei anzeigen

@ -0,0 +1,42 @@
package de.quantumnanox.warshipfactory.main;
import java.lang.reflect.Field;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
public class CommandRemover {
private static String packageName = Bukkit.getServer().getClass().getPackage().getName();
private static String version = packageName.substring(packageName.lastIndexOf(".") + 1);
public static void removeAll(String... cmds) throws Exception {
for (int i = 0; i < cmds.length; i++)
removeCommand(cmds[i]);
}
/**
* Removes command from bukkit CommandMap
*
* @param command Command to remove
* @return
* @throws Exception
*/
public static boolean removeCommand(String command) throws Exception {
Class<?> serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands");
f2.setAccessible(true);
Map<String, Command> knownCommands = (Map<String, Command>) f2.get(commandMap);
return knownCommands.remove(command.toLowerCase()) != null;
}
}

Datei anzeigen

@ -0,0 +1,118 @@
package de.quantumnanox.warshipfactory.main;
import java.lang.reflect.Field;
import java.util.HashMap;
import net.thecobix.tag.Tag;
import net.thecobix.tag.TagCompound;
public class Registry<T extends CobixTagFormatSupported> extends CobixTagFormatSupported {
Class<T> clazz;
Field idfield;
public Registry(Class<T> clazz1, String name) {
this.clazz = clazz1;
this.name = name;
try {
this.idfield = clazz.getDeclaredField("regId");
} catch (NoSuchFieldException | SecurityException e) {
throw new IllegalArgumentException("The class that is extending CobixTagFormatSupported must have a field named regId", e);
}
}
private HashMap<Integer, T> entries = new HashMap<>();
private String name;
public int register(T object) {
int id = getFreeID();
if(id == -1) throw new RuntimeException("Registry limit of "+Integer.MAX_VALUE+" entries exceeded.");
if(idfield.isAccessible()) {
try {
idfield.set(object, id);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
} else {
idfield.setAccessible(true);
try {
idfield.set(object, id);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
idfield.setAccessible(false);
}
entries.put(id, object);
return id;
}
public T get(int id) {
return entries.get(id);
}
public HashMap<Integer, T> getAll() {
return entries;
}
private int getFreeID() {
for (int i = 0; i < Integer.MAX_VALUE; i++) {
if(entries.get(i) == null) return i;
}
return -1;
}
@Override
public TagCompound save() {
TagCompound out = new TagCompound(name);
for(Integer id : entries.keySet()) {
out.put(entries.get(id).save());
}
return out;
}
@Override
public void load(TagCompound tc) {
if(tc == null) return;
for(Tag t : tc) {
if(t instanceof TagCompound == false) {
continue;
}
try {
int id = Integer.parseInt(t.getName());
T obj = clazz.newInstance();
obj.load((TagCompound) t);
if(idfield.isAccessible()) {
try {
idfield.set(obj, id);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
} else {
idfield.setAccessible(true);
try {
idfield.set(obj, id);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
idfield.setAccessible(false);
}
entries.put(id, obj);
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void unregister(int id) {
entries.remove(id);
}
public int getID(T obj) {
for(Integer id : entries.keySet()) {
if(obj.equals(entries.get(id))) return id;
}
return -1;
}
}

Datei anzeigen

@ -0,0 +1,352 @@
package de.quantumnanox.warshipfactory.main;
import de.pro_crafting.commandframework.CommandArgs;
import de.pro_crafting.commandframework.CommandFramework;
import de.pro_crafting.commandframework.Completer;
import de.pro_crafting.sawe.RegionListener;
import de.quantumnanox.warshipfactory.commands.*;
import de.quantumnanox.warshipfactory.config.Config;
import de.quantumnanox.warshipfactory.content.FactoryWorld;
import net.thecobix.tag.Tag;
import net.thecobix.tag.TagCompound;
import net.thecobix.tag.TagInputStream;
import net.thecobix.tag.TagOutputStream;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public class WarShipFactory extends JavaPlugin implements Listener {
public static final String S_PREFIX = "§8[§3BauFactory§8] §7";
public Config config;
private CommandFramework cmdFramework;
public Registry<FactoryWorld> factoryWorlds = new Registry<>(FactoryWorld.class, "worlds");
private BungeeUtil bungeeUtil;
public File regions = new File("plugins/WarShipFactory", "regions.data");
public FileConfiguration getRegionData = YamlConfiguration.loadConfiguration(regions);
private static WarShipFactory plugin;
public void saveRegionData() {
try { getRegionData.save(regions); } catch (Exception ex) { }
}
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new CommandGui(), this);
File checkFile = new File("plugins/WarShipFactory", "regions.data");
if(!checkFile.exists()) {
getRegionData.options().header("Config auf dieser Basis unendlich erweiterbar");
getRegionData.set("schematic.resetall.position.X", " ");
getRegionData.set("schematic.resetall.position.Y", " ");
getRegionData.set("schematic.resetall.position.Z", " ");
getRegionData.set("schematic.resetall.schematic", " ");
getRegionData.set("regions.wargear1mini.position.X", " ");
getRegionData.set("regions.wargear1mini.position.Y", " ");
getRegionData.set("regions.wargear1mini.position.Z", " ");
getRegionData.set("regions.wargear1mini.schematic.testblock", " ");
getRegionData.set("regions.wargear1mini.schematic.reset", " ");
getRegionData.set("regions.wargear1standart.position.X", " ");
getRegionData.set("regions.wargear1standart.position.Y", " ");
getRegionData.set("regions.wargear1standart.position.Z", " ");
getRegionData.set("regions.wargear1standart.schematic.testblock", " ");
getRegionData.set("regions.wargear1standart.schematic.reset", " ");
getRegionData.set("regions.airship1.position.X", " ");
getRegionData.set("regions.airship1.position.Y", " ");
getRegionData.set("regions.airship1.position.Z", " ");
getRegionData.set("regions.airship1.schematic.testblock", " ");
getRegionData.set("regions.airship1.schematic.reset", " ");
saveRegionData();
}
log("Bootstrap", "BauFactory v" + getDescription().getVersion() + " by Exceptionflug | updatet by. RedstoneTechnik.");
// Time to replace the vanillacommands with WarShipFactory's own versions
try {
CommandRemover.removeCommand("tp");
CommandInjector.injectCommand(new CommandTeleport());
CommandRemover.removeCommand("gamemode");
CommandInjector.injectCommand(new CommandGamemode());
} catch (Exception e1) {
log("Bootstrap", "§cError while replacing some bukkit internals with seagiants code:");
e1.printStackTrace();
}
new File("plugins/WarShipFactory/worlds/").mkdirs();
config = new Config();
config.initConfig();
log("Bootstrap", "§aConfig loaded.");
try {
TagInputStream tis = new TagInputStream(new FileInputStream(new File("plugins/WarShipFactory/backend.ctf")), TagInputStream.GZIP);
List<Tag> tags = tis.readTags();
tis.close();
Tag t = (TagCompound) tags.get(0);
factoryWorlds.load((TagCompound) t);
log("Bootstrap", "§aBackend loaded.");
} catch (IOException e) {
log("Bootstrap", "§cLoading backend failed:");
e.printStackTrace();
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
try {
TagOutputStream tos = new TagOutputStream(
new FileOutputStream(new File("plugins/WarShipFactory/backend.ctf")), TagOutputStream.GZIP);
tos.write(factoryWorlds.save());
tos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}, 60, 60);
for (FactoryWorld fw : factoryWorlds.getAll().values()) {
File f = new File(fw.getWorldAddress());
if (f.exists() && f.isDirectory()) {
File bck = new File("plugins/WarShipFactory/worlds/" + fw.getWorldAddress());
if (bck.exists() && bck.isDirectory()) {
try {
log("Bootstrap", "§9Removing dead world " + fw.getWorldAddress());
FileUtils.deleteDirectory(f);
} catch (IOException e) {
log("Bootstrap", "§cAn error occured while removing dead world " + fw.getWorldAddress());
e.printStackTrace();
}
} else {
File lvlDat = new File(fw.getWorldAddress() + "/level.dat");
if (lvlDat.exists()) {
try {
log("Bootstrap", "§9Fixing dead world " + fw.getWorldAddress());
FileUtils.moveDirectory(f, bck);
} catch (IOException e) {
log("Bootstrap", "§cAn error occured while fixing dead world " + fw.getWorldAddress());
e.printStackTrace();
}
} else {
log("Bootstrap", "§4Corrupt world " + fw.getWorldAddress() + " :( I'm sorry. I can't do anything to recover it...");
try {
FileUtils.deleteDirectory(f);
} catch (IOException e) {
log("Bootstrap", "§cAn error occured while removing dead world " + fw.getWorldAddress());
e.printStackTrace();
}
}
}
}
}
cmdFramework = new CommandFramework(this);
cmdFramework.setInGameOnlyMessage(S_PREFIX + "Dieser Befehl darf nur Ingame verwendet werden!");
cmdFramework.setNoPermMessage("Unknown command. Type \"/help\" for help.");
Bukkit.getPluginManager().registerEvents(this, this);
Method[] methods = this.getClass().getMethods();
for (Method m : methods) {
if (m.getName().equalsIgnoreCase("completeCommands")) {
this.cmdFramework.registerCompleter("bau", m, this);
}
}
cmdFramework.registerCommands(new CommandBau());
log("Bootstrap", "§aCommand framework initiated.");
Bukkit.getPluginManager().registerEvents(new RegionListener(this), this);
log("Bootstrap", "§aSaWe initiated.");
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
public void run() {
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
Date d = new Date();
if (df.format(d).equalsIgnoreCase("23:55:00")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 5 Minuten neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:00")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 1 Minute neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:30")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 30 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:50")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 10 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:55")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 5 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:56")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 4 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:57")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 3 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:58")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 2 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("23:59:59")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet in 1 Sekunden neu.");
}
if (df.format(d).equalsIgnoreCase("00:00:00")) {
Bukkit.broadcastMessage(S_PREFIX + "Der Server startet neu.");
for (Player p : Bukkit.getOnlinePlayers()) {
bungeeUtil.sendToServer(p, config.cfg.getString("Lobby.name"));
}
}
if (df.format(d).equalsIgnoreCase("00:00:05")) {
Bukkit.spigot().restart();
}
}
}, 20L, 20L);
plugin = this;
}
public static WarShipFactory getPlugin() {
return plugin;
}
public static WorldEditPlugin getWorldEdit() {
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
}
public static WorldGuardPlugin getWorldGuard() {
return (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard");
}
@Override
public void onDisable() {
for (FactoryWorld fw : factoryWorlds.getAll().values()) {
if (fw.getWrapped() != null) {
log("Shutdown", "Unloading world " + fw.getWorldAddress());
fw.unloadWorld();
}
}
}
public static void log(String section, String msg) {
Bukkit.getConsoleSender().sendMessage("[WSF | " + section + "] " + msg);
}
public static WarShipFactory getInstance() {
return JavaPlugin.getPlugin(WarShipFactory.class);
}
public FactoryWorld getWorldByAddress(String address) {
for (FactoryWorld fw : factoryWorlds.getAll().values()) {
if (fw.getWorldAddress().equals(address))
return fw;
}
return null;
}
public FactoryWorld getWorldFromOwner(UUID ownaz) {
for (FactoryWorld fw : factoryWorlds.getAll().values()) {
if (fw.getOwner().equals(ownaz))
return fw;
}
return null;
}
@Completer(name = "bau")
public List<String> completeCommands(CommandArgs args) {
List<String> ret = new ArrayList<String>();
String label = args.getCommand().getLabel();
for (String arg : args.getArgs()) {
label += " " + arg;
}
for (String currentLabel : this.cmdFramework.getCommandLabels()) {
String current = currentLabel.replace('.', ' ');
if (currentLabel.contains("BauFactory"))
continue;
if (current.contains(label)) {
current = current.substring(label.lastIndexOf(' ')).trim();
current = current.substring(0, current.indexOf(' ') != -1 ? current.indexOf(' ') : current.length())
.trim();
if (!ret.contains(current)) {
ret.add(current);
}
}
}
return ret;
}
public static class CommandInjector {
private static String packageName = Bukkit.getServer().getClass().getPackage().getName();
private static String version;
static {
version = packageName.substring(packageName.lastIndexOf(".") + 1);
}
public static void injectCommand(Command cmd) throws Exception {
Class serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
commandMap.register("baufactory", cmd);
}
}
@EventHandler
public void onDeath(PlayerDeathEvent e) {
e.setDeathMessage(null);
}
@EventHandler
public void onRespawn(PlayerRespawnEvent e) {
Player p = e.getPlayer();
FactoryWorld fw = getWorldByAddress(p.getWorld().getName());
if (fw != null) {
e.setRespawnLocation(fw.getWrapped().getSpawnLocation());
}
}
@EventHandler
public void onJoin(PlayerJoinEvent e) throws SQLException {
Player p = e.getPlayer();
p.teleport(config.spawn);
p.getInventory().clear();
}
@EventHandler
public void onTpGM3(PlayerTeleportEvent e) {
if (e.getPlayer().hasPermission("bukkit.command.teleport")) {
return;
}
if (e.getCause() == TeleportCause.SPECTATE) {
e.setCancelled(true);
e.getPlayer().sendMessage(WarShipFactory.S_PREFIX + "§cDu darfst die GM3 Teleportfunktion nicht benutzen!");
}
}
}

Datei anzeigen

@ -0,0 +1,146 @@
package net.thecobix.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Map.Entry;
public abstract class Extension {
public static ArrayList<Extension> extensions = new ArrayList<>();
public abstract Tag readTag(Class<? extends Tag> clazz, byte[] data) throws IOException;
public abstract Entry<Class<? extends Tag>, byte[]> splitData(DataInputStream dis, int id, byte[] data, int start) throws IOException;
protected static byte[] subSequence(byte[] fully, int start, int end) {
byte[] out = new byte[(end - start)+2];
int ind = -1;
for(int i = 0; i < fully.length; i++)
{
if(i >= start && i <= end) {
ind ++;
out[ind] = fully[i];
}
}
return out;
}
protected byte[] readByteArray(DataInputStream in) {
try
{
return read(in, readVarInt(in));
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
protected void writeVarInt(DataOutputStream out, int paramInt) throws IOException {
while (true) {
if ((paramInt & 0xFFFFFF80) == 0) {
out.writeByte(paramInt);
return;
}
out.writeByte(paramInt & 0x7F | 0x80);
paramInt >>>= 7;
}
}
protected String readString(DataInputStream dis)
{
int i = 0;
try
{
i = readVarInt(dis);
}
catch (IOException e)
{
e.printStackTrace();
}
if (i < 0)
{
throw new NullPointerException("The received encoded string buffer length is less than zero! Weird string!");
}
else
{
String s = new String(read(dis, i), StandardCharsets.UTF_8);
return s;
}
}
protected byte[] read(DataInputStream in, int amount) {
byte[] out = new byte[amount];
for(int i = 0; i < out.length; i++)
{
try
{
out[i] = in.readByte();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return out;
}
protected int readVarInt(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
while (true) {
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return i;
}
protected int readVarIntSize(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
int s = 0;
while (true) {
s ++;
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return s;
}
protected Entry<Integer, Integer> readVarIntAndSize(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
int s = 0;
while (true) {
s ++;
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return new AbstractMap.SimpleEntry(s, i);
}
public static boolean isRegistered(Class<? extends Extension> clazz) {
for(Extension e : extensions) {
try {
e.getClass().asSubclass(clazz);
return true;
} catch(ClassCastException ex) {
continue;
}
}
return false;
}
}

Datei anzeigen

@ -0,0 +1,164 @@
package net.thecobix.tag;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.Map.Entry;
public abstract class Tag {
/*
* Tag ids:
*
* 0x01: String
* 0x02: Int
* 0x03: Double
* 0x04: Long
* 0x05: Short
* 0x06: Float
* 0x07: Compound
* 0x08: Serializeable
* 0x09: ByteArray
*
*/
public Tag(String name)
{
this.name = name;
}
protected String name;
protected Object value;
protected abstract byte[] write() throws IOException;
protected abstract void read(byte[] data) throws IOException;
public String getName()
{
return name;
}
public Object getValue()
{
return value;
}
protected void writeString(DataOutputStream out, String string, Charset charset) throws IOException {
byte [] bytes = string.getBytes(charset);
writeVarInt(out, bytes.length);
out.write(bytes);
}
protected byte[] readByteArray(DataInputStream in) {
try
{
return read(in, readVarInt(in));
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
protected void writeVarInt(DataOutputStream out, int paramInt) throws IOException {
while (true) {
if ((paramInt & 0xFFFFFF80) == 0) {
out.writeByte(paramInt);
return;
}
out.writeByte(paramInt & 0x7F | 0x80);
paramInt >>>= 7;
}
}
protected String readString(DataInputStream dis)
{
int i = 0;
try
{
i = readVarInt(dis);
}
catch (IOException e)
{
e.printStackTrace();
}
if (i < 0)
{
throw new NullPointerException("The received encoded string buffer length is less than zero! Weird string!");
}
else
{
String s = new String(read(dis, i), StandardCharsets.UTF_8);
return s;
}
}
protected byte[] read(DataInputStream in, int amount) {
byte[] out = new byte[amount];
for(int i = 0; i < out.length; i++)
{
try
{
out[i] = in.readByte();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return out;
}
protected int readVarInt(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
while (true) {
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return i;
}
protected int readVarIntSize(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
int s = 0;
while (true) {
s ++;
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return s;
}
protected Entry<Integer, Integer> readVarIntAndSize(DataInputStream in) throws IOException {
int i = 0;
int j = 0;
int s = 0;
while (true) {
s ++;
int k = in.readByte();
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new RuntimeException("VarInt too big");
if ((k & 0x80) != 128) break;
}
return new AbstractMap.SimpleEntry(s, i);
}
@Override
public String toString()
{
return "Tag "+name+" with value "+value.toString();
}
}

Datei anzeigen

@ -0,0 +1,53 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class TagByteArray extends Tag {
public static final TagByteArray BASE_OBJECT = new TagByteArray("base", "base".getBytes());
public TagByteArray(String name, byte[] data)
{
super(name);
value = data;
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x09);
writeString(dos, this.name, StandardCharsets.UTF_8);
writeVarInt(dos, getValue().length);
dos.write(getValue());
return buffer.toByteArray();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x09)
throw new IllegalStateException("Data is not representing the type TagByteArray");
this.name = readString(dis);
setValue(readByteArray(dis));
}
@Override
public byte[] getValue()
{
return (byte[]) super.getValue();
}
public void setValue(byte[] data) {
this.value = data;
}
}

Datei anzeigen

@ -0,0 +1,275 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class TagCompound extends Tag implements Iterable<Tag> {
public static final TagCompound BASE_OBJECT = new TagCompound("base");
public TagCompound(String name)
{
super(name);
this.value = new ArrayList<Tag>();
}
@Override
protected byte[] write() throws IOException
{
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x07);
writeString(dos, this.name, StandardCharsets.UTF_8);
ArrayList<Byte> bytes = new ArrayList<>();
for(Tag t : tags) {
byte[] all = t.write();
for(int i = 0; i < all.length; i++)
{
bytes.add(all[i]);
}
}
Byte[] ba = bytes.toArray(new Byte[bytes.size()]);
writeVarInt(dos, ba.length);
dos.write(toPrimitives(ba));
return buffer.toByteArray();
}
byte[] toPrimitives(Byte[] oBytes)
{
byte[] bytes = new byte[oBytes.length];
for(int i = 0; i < oBytes.length; i++) {
bytes[i] = oBytes[i];
}
return bytes;
}
byte[] addElement(byte[] a, byte e) {
a = Arrays.copyOf(a, a.length + 1);
a[a.length - 1] = e;
return a;
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x07)
throw new IllegalStateException("Data is not representing the type TagCompound");
this.name = readString(dis);
byte[] ba = readByteArray(dis);
this.value = (ArrayList<Tag>) TagInputStream.readTags(ba);
}
public TagString getTagString(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagString) {
if(t.getName().equals(name)) {
return (TagString) t;
}
}
}
return null;
}
public TagInt getTagInt(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagInt) {
if(t.getName().equals(name)) {
return (TagInt) t;
}
}
}
return null;
}
public TagDouble getTagDouble(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagDouble) {
if(t.getName().equals(name)) {
return (TagDouble) t;
}
}
}
return null;
}
public TagShort getTagShort(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagShort) {
if(t.getName().equals(name)) {
return (TagShort) t;
}
}
}
return null;
}
public TagLong getTagLong(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagLong) {
if(t.getName().equals(name)) {
return (TagLong) t;
}
}
}
return null;
}
public TagFloat getTagFloat(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagFloat) {
if(t.getName().equals(name)) {
return (TagFloat) t;
}
}
}
return null;
}
public TagByteArray getTagByteArray(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagByteArray) {
if(t.getName().equals(name)) {
return (TagByteArray) t;
}
}
}
return null;
}
public TagCompound getTagCompound(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagCompound) {
if(t.getName().equals(name)) {
return (TagCompound) t;
}
}
}
return null;
}
public TagSerializeableObject getTagSerializeableObject(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t instanceof TagSerializeableObject) {
if(t.getName().equals(name)) {
return (TagSerializeableObject) t;
}
}
}
return null;
}
public Tag getTag(String name) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t.getName().equals(name)) {
return t;
}
}
return null;
}
public void put(Tag tag) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
Tag t;
if((t = getTag(tag.getName())) != null) {
((ArrayList<Tag>)this.value).remove(t);
}
tags.add(tag);
this.value = tags;
}
public void putString(String name, String value) {
put(new TagString(name, value));
}
public void putDouble(String name, Double value) {
put(new TagDouble(name, value));
}
public void putInt(String name, Integer value) {
put(new TagInt(name, value));
}
public void putLong(String name, Long value) {
put(new TagLong(name, value));
}
public void putShort(String name, Short value) {
put(new TagShort(name, value));
}
public void putFloat(String name, Float value) {
put(new TagFloat(name, value));
}
public void putFloat(String name, byte[] value) {
put(new TagByteArray(name, value));
}
public void putSerializeableObject(String name, Serializable value) {
put(new TagSerializeableObject(name, value));
}
@Override
public Iterator<Tag> iterator()
{
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
return new Iterator<Tag>() {
int index = -1;
@Override
public boolean hasNext()
{
int vIndex = index;
vIndex ++;
try {
tags.get(vIndex);
return true;
} catch(Exception e) {
return false;
}
}
@Override
public Tag next()
{
index ++;
return tags.get(index);
}
};
}
public <T> T getTag(String name, T type) {
ArrayList<Tag> tags = (ArrayList<Tag>) this.value;
for(Tag t : tags) {
if(t.getName().equals(name) && type.getClass().getName().equals(t.getClass().getName())) {
return (T) t;
}
}
return null;
}
}

Datei anzeigen

@ -0,0 +1,64 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class TagDouble extends Tag {
public static final TagDouble BASE_OBJECT = new TagDouble("base", 0);
public TagDouble(String name, double value)
{
super(name);
this.value = new Double(value);
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x03);
writeString(dos, this.name, StandardCharsets.UTF_8);
byte[] vl = toByteArray(getValue());
writeVarInt(dos, vl.length);
dos.write(vl);
return buffer.toByteArray();
}
private byte[] toByteArray(double d) {
byte[] bytes = new byte[8];
ByteBuffer.wrap(bytes).putDouble(d);
return bytes;
}
private double toDouble(byte[] b) {
return ByteBuffer.wrap(b).getDouble();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x03)
throw new IllegalStateException("Data is not representing the type TagDouble");
this.name = readString(dis);
byte[] ba = readByteArray(dis);
this.value = new Double(toDouble(ba));
}
public Double getValue() {
return (Double) this.value;
}
public void setValue(double value) {
this.value = new Double(value);
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class TagFloat extends Tag {
public static final TagFloat BASE_OBJECT = new TagFloat("base", 0);
public TagFloat(String name, float value)
{
super(name);
this.value = new Float(value);
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x06);
writeString(dos, this.name, StandardCharsets.UTF_8);
dos.writeFloat((float) this.value);
return buffer.toByteArray();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x06)
throw new IllegalStateException("Data is not representing the type TagFloat");
this.name = readString(dis);
this.value = new Float(dis.readFloat());
}
public Float getValue() {
return (Float) this.value;
}
public void setValue(float value) {
this.value = new Float(value);
}
}

Datei anzeigen

@ -0,0 +1,349 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class TagInputStream extends InputStream {
private InputStream wrapped;
public static final int NONE = 0;
public static final int GZIP = 1;
@Deprecated
public static final int ZIP = 2;
public static final int BASE64 = 3;
private boolean base = false;
private boolean zip = false;
private boolean entry = false;
public TagInputStream(InputStream in, int compression)
{
if(compression == GZIP) {
try
{
this.wrapped = new GZIPInputStream(in);
}
catch (IOException e)
{
e.printStackTrace();
}
return;
} else if(compression == ZIP) {
throw new RuntimeException("ZIP reading not supported yet.");
} else if(compression == BASE64) {
this.base = true;
}
this.wrapped = in;
}
@Override
public int read() throws IOException
{
return this.wrapped.read();
}
@Override
public int read(byte[] b, int off, int len) throws IOException
{
return this.wrapped.read(b, off, len);
}
@Override
public void close() throws IOException
{
this.wrapped.close();
}
@Override
public int available() throws IOException
{
return this.wrapped.available();
}
@Override
public long skip(long n) throws IOException
{
return this.wrapped.skip(n);
}
@Override
public boolean markSupported()
{
return this.wrapped.markSupported();
}
@Override
public synchronized void mark(int readlimit)
{
this.wrapped.mark(readlimit);
}
@Override
public synchronized void reset() throws IOException
{
this.wrapped.reset();
}
@Override
public int read(byte[] b) throws IOException
{
return this.wrapped.read(b);
}
public List<Tag> readTags() throws IOException {
ArrayList<Tag> out = new ArrayList<>();
byte[] data = readFully(this.wrapped, -1, true);
if(this.base) {
data = Base64.getDecoder().decode(data);
}
ArrayList<Entry<Class<? extends Tag>, byte[]>> mapped = splitData(data);
for(Entry<Class<? extends Tag>, byte[]> e : mapped) {
Class clazz = e.getKey();
if(clazz.getSimpleName().equals("TagString")) {
TagString ts = new TagString("", "");
ts.read(e.getValue());
out.add(ts);
} else if(clazz.getSimpleName().equals("TagInt")) {
TagInt ti = new TagInt("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagDouble")) {
TagDouble ti = new TagDouble("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagLong")) {
TagLong ti = new TagLong("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagShort")) {
TagShort ti = new TagShort("", (short) 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagFloat")) {
TagFloat ti = new TagFloat("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagCompound")) {
TagCompound ti = new TagCompound("");
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagSerializeableObject")) {
TagSerializeableObject ti = new TagSerializeableObject("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagByteArray")) {
TagByteArray ti = new TagByteArray("", new byte[] {});
ti.read(e.getValue());
out.add(ti);
} else {
if(Extension.extensions.size() != 0) {
Tag shoutie = null;
for(Extension ex : Extension.extensions) {
Tag honey = ex.readTag(clazz, e.getValue());
if(honey != null) {
shoutie = honey;
}
}
out.add(shoutie);
} else {
System.out.println("[ERROR] Unknown tag with classname "+clazz.getSimpleName());
}
}
}
return out;
}
public static List<Tag> readTags(byte[] data) throws IOException {
ArrayList<Tag> out = new ArrayList<>();
ArrayList<Entry<Class<? extends Tag>, byte[]>> mapped = splitData(data);
for(Entry<Class<? extends Tag>, byte[]> e : mapped) {
Class clazz = e.getKey();
if(clazz.getSimpleName().equals("TagString")) {
TagString ts = new TagString("", "");
ts.read(e.getValue());
out.add(ts);
} else if(clazz.getSimpleName().equals("TagInt")) {
TagInt ti = new TagInt("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagDouble")) {
TagDouble ti = new TagDouble("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagLong")) {
TagLong ti = new TagLong("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagShort")) {
TagShort ti = new TagShort("", (short) 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagFloat")) {
TagFloat ti = new TagFloat("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagCompound")) {
TagCompound ti = new TagCompound("");
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagSerializeableObject")) {
TagSerializeableObject ti = new TagSerializeableObject("", 0);
ti.read(e.getValue());
out.add(ti);
} else if(clazz.getSimpleName().equals("TagByteArray")) {
TagByteArray ti = new TagByteArray("", new byte[] {});
ti.read(e.getValue());
out.add(ti);
} else {
if(Extension.extensions.size() != 0) {
Tag shoutie = null;
for(Extension ex : Extension.extensions) {
Tag honey = ex.readTag(clazz, e.getValue());
if(honey != null) {
shoutie = honey;
}
}
out.add(shoutie);
} else {
System.out.println("[ERROR] Unknown tag with classname "+clazz.getSimpleName());
}
}
}
return out;
}
private static byte[] readFully(InputStream is, int length, boolean readAll)
throws IOException {
byte[] output = {};
if (length == -1) length = Integer.MAX_VALUE;
int pos = 0;
while (pos < length) {
int bytesToRead;
if (pos >= output.length) { // Only expand when there's no room
bytesToRead = Math.min(length - pos, output.length + 1024);
if (output.length < pos + bytesToRead) {
output = Arrays.copyOf(output, pos + bytesToRead);
}
} else {
bytesToRead = output.length - pos;
}
int cc = is.read(output, pos, bytesToRead);
if (cc < 0) {
if (readAll && length != Integer.MAX_VALUE) {
throw new EOFException("Detect premature EOF");
} else {
if (output.length != pos) {
output = Arrays.copyOf(output, pos);
}
break;
}
}
pos += cc;
}
return output;
}
static ArrayList<Entry<Class<? extends Tag>, byte[]>> splitData(byte[] data) throws IOException {
TagCompound tc = new TagCompound("dummy");
ByteArrayInputStream bis = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bis);
ArrayList<Entry<Class<? extends Tag>, byte[]>> out = new ArrayList<>();
while(bis.available() != 0) {
try {
int start = data.length - bis.available();
int id = tc.readVarInt(dis);
tc.readString(dis);
if(id == 0x01) {
tc.readString(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagString.class, subSequence(data, start, end)));
} else if(id == 0x02) {
tc.readVarInt(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagInt.class, subSequence(data, start, end)));
} else if(id == 0x03) {
tc.readByteArray(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagDouble.class, subSequence(data, start, end)));
} else if(id == 0x04) {
tc.readByteArray(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagLong.class, subSequence(data, start, end)));
} else if(id == 0x05) {
dis.readShort();
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagShort.class, subSequence(data, start, end)));
} else if(id == 0x06) {
dis.readFloat();
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagFloat.class, subSequence(data, start, end)));
} else if(id == 0x07) {
tc.readByteArray(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagCompound.class, subSequence(data, start, end)));
} else if(id == 0x08) {
tc.readByteArray(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagSerializeableObject.class, subSequence(data, start, end)));
} else if(id == 0x09) {
tc.readByteArray(dis);
int end = data.length - bis.available();
out.add(new AbstractMap.SimpleEntry(TagByteArray.class, subSequence(data, start, end)));
} else {
if(Extension.extensions.size() != 0) {
Entry<Class<? extends Tag>, byte[]> et = null;
for(Extension e : Extension.extensions) {
Entry<Class<? extends Tag>, byte[]> tet = e.splitData(dis, id, data, start);
if(tet != null) {
et = tet;
}
}
if(et != null) {
out.add(et);
} else {
System.out.println("[ERROR] Unknown tag with id "+id);
}
} else {
System.out.println("[ERROR] Unknown tag with id "+id);
}
}
} catch(Exception e) {
e.printStackTrace();
break;
}
}
return out;
}
private static byte[] subSequence(byte[] fully, int start, int end) {
byte[] out = new byte[(end - start)+2];
int ind = -1;
for(int i = 0; i < fully.length; i++)
{
if(i >= start && i <= end) {
ind ++;
out[ind] = fully[i];
}
}
return out;
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class TagInt extends Tag {
public static final TagInt BASE_OBJECT = new TagInt("base", 0);
public TagInt(String name, int value)
{
super(name);
this.value = new Integer(value);
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x02);
writeString(dos, this.name, StandardCharsets.UTF_8);
writeVarInt(dos, (int) this.value);
return buffer.toByteArray();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x02)
throw new IllegalStateException("Data is not representing the type TagInt");
this.name = readString(dis);
this.value = new Integer(readVarInt(dis));
}
public Integer getValue() {
return (Integer) this.value;
}
public void setValue(int value) {
this.value = new Integer(value);
}
}

Datei anzeigen

@ -0,0 +1,65 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
public class TagLong extends Tag {
public static final TagLong BASE_OBJECT = new TagLong("base", 0);
public TagLong(String name, long value)
{
super(name);
this.value = new Long(value);
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x04);
writeString(dos, this.name, StandardCharsets.UTF_8);
byte[] b = toByteArray((long) this.value);
writeVarInt(dos, b.length);
dos.write(b);
return buffer.toByteArray();
}
private byte[] toByteArray(long l) {
byte[] b = new byte[8];
ByteBuffer.wrap(b).putLong(l);
return b;
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x04)
throw new IllegalStateException("Data is not representing the type TagLong");
this.name = readString(dis);
byte[] ba = readByteArray(dis);
this.value = new Long(toLong(ba));
}
private long toLong(byte[] ba)
{
return ByteBuffer.wrap(ba).getLong();
}
public Long getValue() {
return (Long) this.value;
}
public void setValue(long value) {
this.value = new Long(value);
}
}

Datei anzeigen

@ -0,0 +1,119 @@
package net.thecobix.tag;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Base64;
import java.util.List;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.print.attribute.standard.Compression;
public class TagOutputStream extends OutputStream {
private OutputStream wrapped;
public static final int NONE = 0;
public static final int GZIP = 1;
public static final int ZIP = 2;
public static final int BASE64 = 3;
private boolean base = false;
private boolean zip = false;
private boolean entry = false;
public TagOutputStream(OutputStream out, int compression)
{
if(compression == GZIP) {
try
{
this.wrapped = new GZIPOutputStream(out);
}
catch (IOException e)
{
e.printStackTrace();
}
return;
} else if(compression == ZIP) {
this.wrapped = new ZipOutputStream(out);
this.zip = true;
return;
} else if(compression == BASE64) {
this.base = true;
}
this.wrapped = out;
}
@Override
public void write(int b) throws IOException
{
this.wrapped.write(b);
}
public void write(Tag tag) throws IOException {
byte[] ba;
if(this.base) {
ba = Base64.getEncoder().encode(tag.write());
} else {
ba = tag.write();
}
if(this.zip) {
ZipOutputStream zout = (ZipOutputStream) this.wrapped;
if(entry == false) {
ZipEntry ze = new ZipEntry("content");
zout.putNextEntry(ze);
}
}
this.wrapped.write(ba);
}
public void write(List<Tag> tags) throws IOException {
for(Tag t : tags) {
write(t);
}
}
public void write(List<Tag> tags, boolean organizeInCompound) throws IOException {
if(organizeInCompound) {
TagCompound tc = new TagCompound("root");
for(Tag t : tags) {
tc.put(t);
}
write(tc);
return;
}
for(Tag t : tags) {
write(t);
}
}
@Override
public void write(byte[] b) throws IOException
{
this.wrapped.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException
{
this.wrapped.write(b, off, len);
}
@Override
public void flush() throws IOException
{
this.wrapped.flush();;
}
@Override
public void close() throws IOException
{
if(this.zip) {
ZipOutputStream zout = (ZipOutputStream) this.wrapped;
zout.closeEntry();
}
this.wrapped.close();
}
}

Datei anzeigen

@ -0,0 +1,72 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
public class TagSerializeableObject extends Tag {
public static final TagSerializeableObject BASE_OBJECT = new TagSerializeableObject("base", 0);
public TagSerializeableObject(String name, Serializable obj)
{
super(name);
this.value = obj;
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x08);
writeString(dos, this.name, StandardCharsets.UTF_8);
byte[] ba = toByteArray((Serializable) this.value);
writeVarInt(dos, ba.length);
dos.write(ba);
return buffer.toByteArray();
}
private byte[] toByteArray(Serializable obj) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
return bos.toByteArray();
}
private Object toObject(byte[] ba) throws IOException, ClassNotFoundException {
ByteArrayInputStream bis = new ByteArrayInputStream(ba);
ObjectInputStream ois = new ObjectInputStream(bis);
return ois.readObject();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x08)
throw new IllegalStateException("Data is not representing the type TagSerializeableObject");
this.name = readString(dis);
byte[] ba = readByteArray(dis);
try
{
this.value = toObject(ba);
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
}
public void setValue(Serializable obj) {
this.value = obj;
}
}

Datei anzeigen

@ -0,0 +1,50 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class TagShort extends Tag {
public static final TagShort BASE_OBJECT = new TagShort("base", (short) 0);
public TagShort(String name, short value)
{
super(name);
this.value = new Short(value);
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x05);
writeString(dos, this.name, StandardCharsets.UTF_8);
dos.writeShort((short) this.value);
return buffer.toByteArray();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x05)
throw new IllegalStateException("Data is not representing the type TagShort");
this.name = readString(dis);
this.value = new Short(dis.readShort());
}
public Short getValue() {
return (Short) this.value;
}
public void setValue(short value) {
this.value = new Short(value);
}
}

Datei anzeigen

@ -0,0 +1,52 @@
package net.thecobix.tag;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.ReadOnlyFileSystemException;
public class TagString extends Tag {
public static final TagString BASE_OBJECT = new TagString("base", "base");
public TagString(String name, String value)
{
super(name);
this.value = value;
}
@Override
protected byte[] write() throws IOException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(buffer);
writeVarInt(dos, 0x01);
writeString(dos, this.name, StandardCharsets.UTF_8);
writeString(dos, (String) this.value, StandardCharsets.UTF_8);
return buffer.toByteArray();
}
@Override
protected void read(byte[] data) throws IOException
{
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(buffer);
if(readVarInt(dis) != 0x01)
throw new IllegalStateException("Data is not representing the type TagString");
this.name = readString(dis);
this.value = readString(dis);
}
public String getValue()
{
return (String) this.value;
}
public void setValue(String value) {
this.value = value;
}
}

9
src/main/java/plugin.yml Normale Datei
Datei anzeigen

@ -0,0 +1,9 @@
name: WarShipFactory
author: Exceptionflug
version: 1.1
depend: [Brew, WorldEdit, WorldGuard]
main: de.quantumnanox.warshipfactory.main.WarShipFactory
commands:
gs:

Datei anzeigen

@ -0,0 +1,38 @@
package de.quantumnanox.WarShipFactory;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}