From 9e2ddeb55321b09086a5a27254197d783847e6e3 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Mon, 25 Apr 2022 18:50:36 +0200 Subject: Initial commit --- .classpath | 36 +++ .gitignore | 171 ++++++++++++ .project | 23 ++ dependency-reduced-pom.xml | 90 +++++++ pom.xml | 102 +++++++ src/main/java/com/encrox/zombie/Commander.java | 56 ++++ src/main/java/com/encrox/zombie/Constants.java | 59 +++++ src/main/java/com/encrox/zombie/Game.java | 294 +++++++++++++++++++++ src/main/java/com/encrox/zombie/GameListener.java | 159 +++++++++++ src/main/java/com/encrox/zombie/Lobby.java | 72 +++++ src/main/java/com/encrox/zombie/Map.java | 118 +++++++++ src/main/java/com/encrox/zombie/Misc.java | 12 + src/main/java/com/encrox/zombie/Mob.java | 41 +++ src/main/java/com/encrox/zombie/Schematic.java | 117 ++++++++ src/main/java/com/encrox/zombie/Zombie.java | 245 +++++++++++++++++ src/main/java/com/encrox/zombie/ZombieWorld.java | 79 ++++++ .../java/com/encrox/zombie/interactable/Chest.java | 27 ++ .../encrox/zombie/interactable/Interactable.java | 23 ++ .../java/com/encrox/zombie/interactable/Lever.java | 38 +++ .../com/encrox/zombie/interactable/Powerup.java | 22 ++ src/main/resources/config.json | 4 + src/main/resources/descriptor.json | 59 +++++ src/main/resources/lang/de-DE.properties | 2 + src/main/resources/lang/en-GB.properties | 28 ++ src/main/resources/plugin.yml | 9 + src/main/resources/schematics/test.schematic | Bin 0 -> 187 bytes target/classes/config.json | 4 + target/classes/descriptor.json | 59 +++++ target/classes/lang/de-DE.properties | 2 + target/classes/lang/en-GB.properties | 28 ++ target/classes/plugin.yml | 9 + target/classes/schematics/test.schematic | Bin 0 -> 187 bytes target/maven-archiver/pom.properties | 5 + .../compile/default-compile/createdFiles.lst | 0 .../compile/default-compile/inputFiles.lst | 15 ++ .../testCompile/default-testCompile/inputFiles.lst | 0 36 files changed, 2008 insertions(+) create mode 100755 .classpath create mode 100644 .gitignore create mode 100755 .project create mode 100755 dependency-reduced-pom.xml create mode 100755 pom.xml create mode 100755 src/main/java/com/encrox/zombie/Commander.java create mode 100755 src/main/java/com/encrox/zombie/Constants.java create mode 100755 src/main/java/com/encrox/zombie/Game.java create mode 100755 src/main/java/com/encrox/zombie/GameListener.java create mode 100755 src/main/java/com/encrox/zombie/Lobby.java create mode 100755 src/main/java/com/encrox/zombie/Map.java create mode 100755 src/main/java/com/encrox/zombie/Misc.java create mode 100755 src/main/java/com/encrox/zombie/Mob.java create mode 100755 src/main/java/com/encrox/zombie/Schematic.java create mode 100755 src/main/java/com/encrox/zombie/Zombie.java create mode 100755 src/main/java/com/encrox/zombie/ZombieWorld.java create mode 100755 src/main/java/com/encrox/zombie/interactable/Chest.java create mode 100755 src/main/java/com/encrox/zombie/interactable/Interactable.java create mode 100755 src/main/java/com/encrox/zombie/interactable/Lever.java create mode 100755 src/main/java/com/encrox/zombie/interactable/Powerup.java create mode 100755 src/main/resources/config.json create mode 100755 src/main/resources/descriptor.json create mode 100755 src/main/resources/lang/de-DE.properties create mode 100755 src/main/resources/lang/en-GB.properties create mode 100755 src/main/resources/plugin.yml create mode 100755 src/main/resources/schematics/test.schematic create mode 100755 target/classes/config.json create mode 100755 target/classes/descriptor.json create mode 100755 target/classes/lang/de-DE.properties create mode 100755 target/classes/lang/en-GB.properties create mode 100755 target/classes/plugin.yml create mode 100755 target/classes/schematics/test.schematic create mode 100755 target/maven-archiver/pom.properties create mode 100755 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100755 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100755 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst diff --git a/.classpath b/.classpath new file mode 100755 index 0000000..16c89cc --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9d02df8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,171 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse,java,windows,linux,macos + +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +replay_pid* + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/eclipse,java,windows,linux,macos diff --git a/.project b/.project new file mode 100755 index 0000000..ff9fa73 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + zombie + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100755 index 0000000..c1adb1e --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + com.encrox + zombie + Zombie + 0.0.1-SNAPSHOT + + + + src/main/resources + + plugin.yml + config.json + descriptor.json + + + + schematics + src/main/resources/schematics + + test.schematic + + + + lang + src/main/resources/lang + + de-DE.properties + en-GB.properties + + + + + + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + maven-shade-plugin + + + package + + shade + + + + + + + + + + org.bukkit + craftbukkit + 1.8 + provided + + + com.sk89q + worldedit + 6.1.5 + provided + + + com.sk89q + worldguard + 6.2 + provided + + + com.comphenix + protocollib + 4.2.1 + provided + + + com.encrox + instancedregions + 0.0.1-SNAPSHOT + provided + + + + diff --git a/pom.xml b/pom.xml new file mode 100755 index 0000000..27724f8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,102 @@ + + 4.0.0 + com.encrox + zombie + 0.0.1-SNAPSHOT + Zombie + + + org.bukkit + craftbukkit + 1.8 + provided + + + com.sk89q + worldedit + 6.1.5 + provided + + + com.sk89q + worldguard + 6.2 + provided + + + com.comphenix + protocollib + 4.2.1 + provided + + + com.encrox + instancedregions + 0.0.1-SNAPSHOT + provided + + + org.json + json + 20160810 + compile + + + org.jnbt + jnbt + 1.1 + compile + + + + + + src/main/resources + + plugin.yml + config.json + descriptor.json + + + + src/main/resources/schematics + schematics + + test.schematic + + + + src/main/resources/lang + lang + + de-DE.properties + en-GB.properties + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/encrox/zombie/Commander.java b/src/main/java/com/encrox/zombie/Commander.java new file mode 100755 index 0000000..40e77eb --- /dev/null +++ b/src/main/java/com/encrox/zombie/Commander.java @@ -0,0 +1,56 @@ +package com.encrox.zombie; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Commander implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) { + try { + if(sender instanceof Player) { + Player player = (Player)sender; + switch(args[0]) { + case "lobby": + switch(args[1]) { + case "create": + if(player.hasPermission("zombie.create")) { + player.sendMessage(Zombie.createLobby(player, args[2], args[3])); + } else { + player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("no_permission")); + } + break; + case "join": + if(player.hasPermission("zombie.join")) { + if(args.length == 3) { + player.sendMessage(Zombie.joinLobby(player, args[2])); + } else { + player.sendMessage(Zombie.listLobbies()); + } + } else { + player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("no_permission")); + } + break; + case "leave": + player.sendMessage(Zombie.removePlayer(player)); + break; + case "start": + player.sendMessage(Zombie.start(player)); + break; + } + break; + } + } else { + sender.sendMessage(Zombie.lang.getProperty("no_player")); + } + } catch(Exception e) { + e.printStackTrace(); + return false; + } + return true; + } + +} diff --git a/src/main/java/com/encrox/zombie/Constants.java b/src/main/java/com/encrox/zombie/Constants.java new file mode 100755 index 0000000..50e7491 --- /dev/null +++ b/src/main/java/com/encrox/zombie/Constants.java @@ -0,0 +1,59 @@ +package com.encrox.zombie; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; + +import com.sk89q.worldedit.blocks.ItemType; + +public class Constants { + + public static class Game { + + public static final Material[] ITEMSET = new Material[] { + Material.WOOD_HOE, + Material.WOOD_PICKAXE, + Material.WOOD_SPADE, + Material.WOOD_SWORD, + Material.STONE_AXE, + Material.STONE_HOE, + Material.STONE_PICKAXE, + Material.STONE_SPADE, + Material.STONE_SWORD, + Material.IRON_AXE, + Material.IRON_HOE, + Material.IRON_PICKAXE, + Material.IRON_SPADE, + Material.IRON_SWORD, + Material.GOLD_AXE, + Material.GOLD_HOE, + Material.GOLD_PICKAXE, + Material.GOLD_SPADE, + Material.GOLD_SWORD, + Material.DIAMOND_AXE, + Material.DIAMOND_HOE, + Material.DIAMOND_PICKAXE, + Material.DIAMOND_SPADE, + Material.DIAMOND_SWORD, + Material.BOW, + Material.ARROW, + Material.LEATHER_HELMET, + Material.LEATHER_CHESTPLATE, + Material.LEATHER_LEGGINGS, + Material.LEATHER_BOOTS, + Material.GOLD_HELMET, + Material.GOLD_CHESTPLATE, + Material.GOLD_LEGGINGS, + Material.GOLD_BOOTS, + Material.IRON_HELMET, + Material.IRON_CHESTPLATE, + Material.IRON_LEGGINGS, + Material.IRON_BOOTS, + Material.CHAINMAIL_HELMET, + Material.CHAINMAIL_CHESTPLATE, + Material.CHAINMAIL_LEGGINGS, + Material.CHAINMAIL_BOOTS + }; + + } + +} diff --git a/src/main/java/com/encrox/zombie/Game.java b/src/main/java/com/encrox/zombie/Game.java new file mode 100755 index 0000000..ae6ff4a --- /dev/null +++ b/src/main/java/com/encrox/zombie/Game.java @@ -0,0 +1,294 @@ +package com.encrox.zombie; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.material.MaterialData; +import org.bukkit.util.BlockVector; + +import com.encrox.instancedregions.InstancedProtectedCuboidRegion; +import com.encrox.zombie.interactable.Chest; +import com.encrox.zombie.interactable.Interactable; +import com.encrox.zombie.interactable.Lever; +import com.encrox.zombie.interactable.Powerup; + +public class Game { + + private volatile ArrayList players, frozen; + private volatile Map map; + private volatile HashMap stats; + private volatile InstancedProtectedCuboidRegion region; + private volatile Mob[] mobs; + private volatile ArrayList mobsRound; + public volatile ArrayList watchdog; + private volatile int round; + private volatile boolean done; + private volatile Interactable[] inters; + private volatile com.sk89q.worldedit.BlockVector min; + + public Game(ArrayList players, Map map) { + this.players = players; + this.map = map; + stats = new HashMap(); + region = Zombie.zombieWorld.allocate(map.getSchematic()); + mobs = map.getMobs(); + mobsRound = new ArrayList(); + watchdog = new ArrayList(); + frozen = new ArrayList(); + BlockVector spawn = map.getSpawn(); + min = region.getMinimumPoint(); + Powerup[] powerups = map.getPowerups(); + Lever[] levers = map.getLevers(); + inters = new Interactable[powerups.length+levers.length+1]; + for(int i = 0; i getPlayers() { + return players; + } + + public void playerDeath(Player player) { + if(!frozen.contains(player)) { + announce(ChatColor.RED + Zombie.lang.getProperty("game_player_fell").replace("%player%", player.getName())); + player.teleport(player.getLocation().add(0, -1, 0)); + player.setHealth(.5); + frozen.add(player); + Bukkit.getScheduler().runTaskTimer(Zombie.plugin, new Runnable() { + int t = 30; + @Override + public void run() { + if(frozen.contains(player)) { + if(t == 0) { + announce(ChatColor.RED + Zombie.lang.getProperty("game_player_died").replace("%player%", player.getName())); + frozen.remove(player); + players.remove(player); + player.setHealth(player.getMaxHealth()); + //TODO: Teleport back outta dungeon + } else { + announce(ChatColor.YELLOW + Zombie.lang.getProperty("game_revive_countdown").replace("%player%", player.getName()).replace("%seconds%", ""+t)); + t-=5; + } + } + } + }, 0, 100); + } + } + + public boolean isFrozen(Player player) { + return frozen.contains(player); + } + + public void revive(Player from, Player to) { + if(frozen.contains(to)) { + frozen.remove(to); + to.teleport(to.getLocation().add(0, -1, 0)); + to.setHealth(to.getMaxHealth()); + } + } + + public void randomizeChest() { + Block block = Zombie.zombieWorld.getWorld().getBlockAt(getAbsoluteLocation(inters[inters.length-1].getBlockVector())); + block.setType(Material.AIR); + block.getState().update(); + Chest relChest = (Chest)Misc.random(map.getChests()); + inters[inters.length-1] = relChest; + block = Zombie.zombieWorld.getWorld().getBlockAt(getAbsoluteLocation(relChest.getBlockVector())); + block.setType(Material.CHEST); + org.bukkit.material.Chest c = new org.bukkit.material.Chest(); + c.setFacingDirection(relChest.getFacing()); + block.setData(c.getData()); + block.getState().update(); + } + + public void announce(String text) { + for(int i = 0, size = players.size(); i stats.put(k, v+amount)); + } + + public int getPoints(Player player) { + if(stats.containsKey(player)) + return stats.get(player); + return -1; + } + + public Location getAbsoluteLocation(BlockVector relative) { + return new Location(Zombie.zombieWorld.getWorld(), min.getX()+relative.getBlockX(), 64+relative.getBlockY(), min.getBlockZ()+relative.getBlockZ()); + } + + /* + public Powerup getPowerup(Block block) { + for(int i = 0; i= cost) { + player.sendMessage(ChatColor.YELLOW + Zombie.lang.getProperty("game_paid").replace("%amount%", ""+cost)); + current.substractPoints(player, cost); + if(inter instanceof Chest) { + if(Math.random() > 0.25) { + ItemStack item = new ItemStack((Material)Misc.random(Constants.Game.ITEMSET)); + Enchantment ench; + while(!(ench = (Enchantment)Misc.random(Enchantment.values())).canEnchantItem(item)); + item.addEnchantment(ench, 1+(new Random().nextInt(Integer.MAX_VALUE)%(ench.getMaxLevel()-1))); + player.getInventory().addItem(item); + } else { + player.getInventory().addItem(new ItemStack(Material.SKULL_ITEM)); + current.randomizeChest(); + } + e.setCancelled(true); + } else if(inter instanceof Powerup) { + Powerup powerup = (Powerup)inter; + player.getInventory().addItem(powerup.getItem()); + } else if(inter instanceof Lever) { + Lever lever = (Lever)inter; + if(lever.isToggled()) { + player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("game_impossible")); + current.addPoints(player, cost); + e.setCancelled(true); + } else { + lever.toggle(); + } + } + } else { + player.sendMessage(ChatColor.RED + Zombie.lang.getProperty("game_no_points").replace("%amount%", ""+cost)); + e.setCancelled(true); + } + } + } + } + } + } catch(Exception ex) { + ex.printStackTrace(); + } + } + + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent e) { + Game current; + Player from = e.getPlayer(); + if(e.getRightClicked() instanceof Player) { + Player to = (Player)e.getRightClicked(); + for(int i = 0, size = Zombie.games.size(); i players; + private Player creator; + private String identifier; + private Map map; + + public Lobby(Player creator, String identifier, Map map) { + this.creator = creator; + this.identifier = identifier; + this.map = map; + players = new ArrayList(); + players.add(creator); + } + + public String getIdentifier() { + return identifier; + } + + public Player getCreator() { + return creator; + } + + public boolean containsPlayer(Player player) { + if(creator.equals(player)) return true; + return players.contains(player); + } + + public void removePlayer(Player player) { + if(creator.equals(player)) { + for(int i = 0, size = players.size(); i entities, tileEntities; + public File file; + + public Schematic(int width, int height, int length, String materials, byte[] blocks, byte[] data, List entities, List tileEntities) { + this.width = width; + this.height = height; + this.length = length; + this.materials = materials; + this.blocks = blocks; + this.data = data; + this.entities = entities; + this.tileEntities = tileEntities; + blockReadIndex = 0; + blockWriteIndex = 0; + dataReadIndex = 0; + dataWriteIndex = 0; + } + + public Schematic(File file) { + this.file = file; + CompoundTag schematicTag = null; + try { + NBTInputStream in = new NBTInputStream(new FileInputStream(file)); + schematicTag = (CompoundTag)in.readTag(); + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Map schematic = schematicTag.getValue(); + width = ((ShortTag)schematic.get("Width")).getValue(); + height = ((ShortTag)schematic.get("Height")).getValue(); + length = ((ShortTag)schematic.get("Length")).getValue(); + materials = ((StringTag)schematic.get("Materials")).getValue(); + blocks = ((ByteArrayTag)schematic.get("Blocks")).getValue(); + data = ((ByteArrayTag)schematic.get("Data")).getValue(); + entities = ((ListTag)schematic.get("Entities")).getValue(); + tileEntities = ((ListTag)schematic.get("TileEntities")).getValue(); + blockReadIndex = 0; + blockWriteIndex = 0; + dataReadIndex = 0; + dataWriteIndex = 0; + } + + public byte getBlockIdAt(int x, int y, int z) { + return blocks[(y*length + z)*width + x]; + } + + public byte getNextBlock() { + return blocks[blockReadIndex++]; + } + + public byte getDataAt(int x, int y, int z) { + return data[(y*length + z)*width + x]; + } + + public byte getNextData() { + return data[dataReadIndex++]; + } + + public void setBlockIdAt(int x, int y, int z, byte blockId) { + blocks[(y*length + z)*width + x] = blockId; + } + + public void setNextBlock(byte blockId) { + blocks[blockWriteIndex++] = blockId; + } + + public void setDataAt(int x, int y, int z, byte newData) { + data[(y*length + z)*width + x] = newData; + } + + public void setNextData(byte newData) { + data[dataWriteIndex++] = newData; + } + + public void write(File file) { + + } + + public void reset() { + blockReadIndex = 0; + blockWriteIndex = 0; + dataReadIndex = 0; + dataWriteIndex = 0; + } + +} diff --git a/src/main/java/com/encrox/zombie/Zombie.java b/src/main/java/com/encrox/zombie/Zombie.java new file mode 100755 index 0000000..d687f6e --- /dev/null +++ b/src/main/java/com/encrox/zombie/Zombie.java @@ -0,0 +1,245 @@ +package com.encrox.zombie; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Properties; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginDescriptionFile; +import org.bukkit.plugin.java.JavaPlugin; +import org.json.JSONArray; +import org.json.JSONObject; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +public class Zombie extends JavaPlugin { + + public static Plugin plugin; + public static Logger logger; + public static PluginDescriptionFile pdf; + public static Properties lang; + public static JSONObject config; + public static JSONArray schematicDescriptors; + public static File schematicsDirectory; + public static WorldEditPlugin we; + public static ArrayList maps; + public static ArrayList lobbies; + public static ArrayList games; + public static ZombieWorld zombieWorld; + public static Commander commander; + + public void onEnable() { + pdf = getDescription(); + logger = Logger.getLogger("Minecraft"); + if(setupMyself() && setupWorldEdit()) { + plugin = this; + commander = new Commander(); + getCommand("zombie").setExecutor(commander); + logger.info(pdf.getName() + " " + pdf.getVersion() + " has been enabled."); + } else { + logger.info(pdf.getName() + " " + pdf.getVersion() + " has been disabled."); + } + } + + public boolean setupWorldEdit() { + we = (WorldEditPlugin)Bukkit.getPluginManager().getPlugin("WorldEdit"); + return (we != null); + } + + public boolean setupMyself() { + if(!this.getDataFolder().exists()) + this.getDataFolder().mkdirs(); + schematicsDirectory = new File(this.getDataFolder(), "schematics"); + if(!schematicsDirectory.exists()) + schematicsDirectory.mkdirs(); + File configFile = new File(this.getDataFolder(), "config.json"); + if(!configFile.exists()) { + BufferedInputStream bis; + FileOutputStream out; + try { + bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("config.json")); + out = new FileOutputStream(configFile); + int current; + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + BufferedReader br; + StringBuilder sb = new StringBuilder(); + String line; + try { + br = new BufferedReader(new FileReader(configFile)); + while((line = br.readLine()) != null) + sb.append(line); + br.close(); + } catch (Exception e1) { + e1.printStackTrace(); + return false; + } + config = new JSONObject(sb.toString()); + zombieWorld = new ZombieWorld(this, Bukkit.getWorld(config.getString("world"))); + File schematicDescriptorFile = new File(schematicsDirectory, "descriptor.json"); + if(!schematicDescriptorFile.exists()) { + int current; + try { + BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("descriptor.json")); + FileOutputStream out = new FileOutputStream(schematicDescriptorFile); + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + try { + BufferedInputStream bis = new BufferedInputStream(getClass().getClassLoader().getResourceAsStream("schematics/test.schematic")); + FileOutputStream out = new FileOutputStream(new File(schematicsDirectory, "test.schematic")); + while((current = bis.read()) != -1) { + out.write(current); + } + bis.close(); + out.close(); + } catch(Exception e) { + e.printStackTrace(); + return false; + } + } + sb = new StringBuilder(); + try { + br = new BufferedReader(new FileReader(schematicDescriptorFile)); + while((line = br.readLine()) != null) + sb.append(line); + br.close(); + } catch (Exception e1) { + e1.printStackTrace(); + return false; + } + schematicDescriptors = new JSONArray(sb.toString()); + lang = new Properties(); + try { + //TODO + lang.load(getClass().getClassLoader().getResourceAsStream("lang/" + config.getString("locale") + ".properties")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return false; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + maps = new ArrayList(); + lobbies = new ArrayList(); + games = new ArrayList(); + for(int i = 0, len = schematicDescriptors.length(); i regions; + private int lastX; + + public ZombieWorld(Plugin plugin, World world) { + this.world = world; + this.plugin = plugin; + regions = new ArrayList(); + lastX = 0; + } + + public InstancedProtectedCuboidRegion allocate(int width, int length) { + BlockVector min, max; + InstancedProtectedCuboidRegion region; + for(int i = 0; true; i+=16) { + if(new ProtectedCuboidRegion("current", (min = new BlockVector(lastX+i, 0, 0)), (max = new BlockVector(lastX+i+width, 255, length))).getIntersectingRegions(regions).isEmpty()) { + region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max); + regions.add(region); + return region; + } + } + } + + public InstancedProtectedCuboidRegion allocate(Schematic schematic) { + BlockVector min, max; + InstancedProtectedCuboidRegion region; + for(int i = 0; true; i+=16) { + if(new ProtectedCuboidRegion("current", (min = new BlockVector(lastX+i, 0, 0)), (max = new BlockVector(lastX+i+schematic.width, 255, schematic.length))).getIntersectingRegions(regions).isEmpty()) { + region = new InstancedProtectedCuboidRegion(plugin, world, ""+min.getBlockX(), min, max); + schematic.reset(); + for(int y = 0; y 2", + "levers": [ 0 ] + } + ], + "chests": [ + { + "position": [ 2, 1, 1 ], + "cost": 1000, + "facing": "SOUTH" + }, + { + "position": [ 3, 1, 2 ], + "cost": 1000, + "facing": "WEST" + }, + { + "position": [ 2, 1, 3 ], + "cost": 1000, + "facing": "NORTH" + } + ], + "powerups": [ + { + "position": [ 3, 2, 2 ], + "item": "DIAMOND_SWORD", + "enchantment": + { + "type": "DAMAGE_ALL", + "level": 1 + }, + "cost": 100 + } + ], + "levers": [ + { + "position": [ 0, 0, 0 ], + "cost": 100, + "toggle": [ ] + } + ] + } +] \ No newline at end of file diff --git a/src/main/resources/lang/de-DE.properties b/src/main/resources/lang/de-DE.properties new file mode 100755 index 0000000..fcce013 --- /dev/null +++ b/src/main/resources/lang/de-DE.properties @@ -0,0 +1,2 @@ +no_player=Dieser Befehl kann nur durch einen Spieler aufgefuehrt werden. +no_permission=Du hast keine Rechte fuer diesen Befehl. diff --git a/src/main/resources/lang/en-GB.properties b/src/main/resources/lang/en-GB.properties new file mode 100755 index 0000000..c382408 --- /dev/null +++ b/src/main/resources/lang/en-GB.properties @@ -0,0 +1,28 @@ +no_player=This command can only be issued by a player. +no_permission=You dont have permission for this command. +lobby_create_success=Lobby has been created. +lobby_create_identifier=A lobby with that identifier already exists. +lobby_create_membership=You are already in a lobby. +lobby_create_map=A map with that name does not exist. +lobby_disbanded=Your lobby has been disbanded. +lobby_leave_success=You have left the lobby. +lobby_leave_membership=You are in no lobby. +lobby_left=%player% left your lobby. +lobby_joined=%player% joined your lobby. +lobby_join_full=The specified lobby is full. +lobby_join_identifier=A lobby with that identifier does not exist. +lobby_join_success=You joined the lobby. +lobby_list=List of lobbies: +lobby_start_success=Game has been started. +lobby_start_failed=You need to be the creator of a lobby to start a game. +game_player_fell=%player% fell. +game_revive_countdown=You got %seconds% seconds left to revive %player%. +game_player_died=%player% died. +game_player_revived=%player1% revived %player2%. +game_round=Round %round% is starting. +game_points_gained=You gained %points% points. +game_points=You have %points% points. +game_paid=You paid %amount% points for this. +game_no_points=You dont have enough points for this. You need at least %amount%. +game_impossible=That action is impossible. Youve been refunded. +plugin_enchantment=The enchantment "%type%" is not applicable on the item "%item%". Ignoring. \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100755 index 0000000..3d187bd --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,9 @@ +main: com.encrox.zombie.Zombie +name: Zombie +version: 1.0 +depend: [InstancedRegions] + +commands: + zombie: + description: Generic zombie command. + usage: /zombie help \ No newline at end of file diff --git a/src/main/resources/schematics/test.schematic b/src/main/resources/schematics/test.schematic new file mode 100755 index 0000000..1b32d4f Binary files /dev/null and b/src/main/resources/schematics/test.schematic differ diff --git a/target/classes/config.json b/target/classes/config.json new file mode 100755 index 0000000..d074011 --- /dev/null +++ b/target/classes/config.json @@ -0,0 +1,4 @@ +{ + "locale": "en-GB", + "world": "instance" +} \ No newline at end of file diff --git a/target/classes/descriptor.json b/target/classes/descriptor.json new file mode 100755 index 0000000..1852c2c --- /dev/null +++ b/target/classes/descriptor.json @@ -0,0 +1,59 @@ +[ + { + "file": "test.schematic", + "name": "testmap", + "players": 4, + "spawn": [ 2, 1, 2 ], + "pointMultiplier": 1.0, + "mobs": [ + { + "position": [ 2, 1, 2 ], + "type": 54, + "rounds": "%round% == 1 || %round% == 2", + "levers": [ ] + }, + { + "position": [ 2, 1, 2 ], + "type": 51, + "rounds": "%round% > 2", + "levers": [ 0 ] + } + ], + "chests": [ + { + "position": [ 2, 1, 1 ], + "cost": 1000, + "facing": "SOUTH" + }, + { + "position": [ 3, 1, 2 ], + "cost": 1000, + "facing": "WEST" + }, + { + "position": [ 2, 1, 3 ], + "cost": 1000, + "facing": "NORTH" + } + ], + "powerups": [ + { + "position": [ 3, 2, 2 ], + "item": "DIAMOND_SWORD", + "enchantment": + { + "type": "DAMAGE_ALL", + "level": 1 + }, + "cost": 100 + } + ], + "levers": [ + { + "position": [ 0, 0, 0 ], + "cost": 100, + "toggle": [ ] + } + ] + } +] \ No newline at end of file diff --git a/target/classes/lang/de-DE.properties b/target/classes/lang/de-DE.properties new file mode 100755 index 0000000..fcce013 --- /dev/null +++ b/target/classes/lang/de-DE.properties @@ -0,0 +1,2 @@ +no_player=Dieser Befehl kann nur durch einen Spieler aufgefuehrt werden. +no_permission=Du hast keine Rechte fuer diesen Befehl. diff --git a/target/classes/lang/en-GB.properties b/target/classes/lang/en-GB.properties new file mode 100755 index 0000000..c382408 --- /dev/null +++ b/target/classes/lang/en-GB.properties @@ -0,0 +1,28 @@ +no_player=This command can only be issued by a player. +no_permission=You dont have permission for this command. +lobby_create_success=Lobby has been created. +lobby_create_identifier=A lobby with that identifier already exists. +lobby_create_membership=You are already in a lobby. +lobby_create_map=A map with that name does not exist. +lobby_disbanded=Your lobby has been disbanded. +lobby_leave_success=You have left the lobby. +lobby_leave_membership=You are in no lobby. +lobby_left=%player% left your lobby. +lobby_joined=%player% joined your lobby. +lobby_join_full=The specified lobby is full. +lobby_join_identifier=A lobby with that identifier does not exist. +lobby_join_success=You joined the lobby. +lobby_list=List of lobbies: +lobby_start_success=Game has been started. +lobby_start_failed=You need to be the creator of a lobby to start a game. +game_player_fell=%player% fell. +game_revive_countdown=You got %seconds% seconds left to revive %player%. +game_player_died=%player% died. +game_player_revived=%player1% revived %player2%. +game_round=Round %round% is starting. +game_points_gained=You gained %points% points. +game_points=You have %points% points. +game_paid=You paid %amount% points for this. +game_no_points=You dont have enough points for this. You need at least %amount%. +game_impossible=That action is impossible. Youve been refunded. +plugin_enchantment=The enchantment "%type%" is not applicable on the item "%item%". Ignoring. \ No newline at end of file diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100755 index 0000000..3d187bd --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,9 @@ +main: com.encrox.zombie.Zombie +name: Zombie +version: 1.0 +depend: [InstancedRegions] + +commands: + zombie: + description: Generic zombie command. + usage: /zombie help \ No newline at end of file diff --git a/target/classes/schematics/test.schematic b/target/classes/schematics/test.schematic new file mode 100755 index 0000000..1b32d4f Binary files /dev/null and b/target/classes/schematics/test.schematic differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100755 index 0000000..820b62c --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Fri May 19 23:00:51 CEST 2017 +version=0.0.1-SNAPSHOT +groupId=com.encrox +artifactId=zombie diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100755 index 0000000..e69de29 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100755 index 0000000..af3adfa --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,15 @@ +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Misc.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Mob.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Lobby.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Zombie.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Map.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\interactable\Chest.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Commander.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\GameListener.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\ZombieWorld.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\interactable\Powerup.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Constants.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\interactable\Interactable.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Schematic.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\Game.java +C:\Users\Superleo1810\workspace\zombie\src\main\java\com\encrox\zombie\interactable\Lever.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100755 index 0000000..e69de29 -- cgit v1.2.1