first commit

This commit is contained in:
BuildTools 2016-09-07 00:08:33 -04:00
parent 20861eb67b
commit 3a007c5ec9
12 changed files with 212 additions and 494 deletions

View file

@ -1 +1 @@
# iieHardcoreWorld # iiePerWorldInventory

View file

@ -1,6 +1,6 @@
main: iie.HelloWorldPlugin main: iie.PerWorldInventoryPlugin
version: 1.0.0 version: 1.0.0
name: HelloWorldPlugin name: PerWorldInventoryPlugin
commands: commands:
HelloWorld: soundtest:
description: Command that says Hello World! description: performs SoundTest

View file

@ -1,150 +0,0 @@
package alisolarflare;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class RandomTP{
private int conflictX;
private int conflictZ;
private int conflictRadius = 70;
private boolean northUsed;
private boolean southUsed;
private boolean eastUsed;
private boolean westUsed;
//every 4 players who use it will be teleported near each other.
//ex. iie > 1200, ali -> 1210, byz -> 1190, charles -> 1195, wind -> 300, zan -> 310, etc
public void conflictRtp(Player player, World world, Location minLocation, Location maxLocation){
//INIT - xDifference, xAverage
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2);
//INIT - zDifference, zAverage
int zdifference = minLocation.getBlockX() - maxLocation.getBlockY();
int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ());
//CHECK - Reset Cycle
if ((northUsed || southUsed || eastUsed || westUsed) == false){
//Tries 20 times to find a location
for(int i = 0; i < 20; i ++){
//INIT - attemptedX, attemptedZ
int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage;
int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage;
int cr = conflictRadius;
//CHECKS - if ground is safe
boolean groundIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER;
boolean northIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ-cr).getType() != Material.WATER;
boolean eastIsSafe = world.getHighestBlockAt(attemptedX+cr, attemptedZ).getType() != Material.WATER;
boolean southIsSafe = world.getHighestBlockAt(attemptedX, attemptedZ+cr).getType() != Material.WATER;
boolean westIsSafe = world.getHighestBlockAt(attemptedX-cr, attemptedZ).getType() != Material.WATER;
//TRANSFER - data to class
if (groundIsSafe && (northIsSafe || southIsSafe || eastIsSafe || westIsSafe)){
northUsed = northIsSafe;
eastUsed = eastIsSafe;
westUsed = westIsSafe;
southUsed = southIsSafe;
conflictX = attemptedX;
conflictZ = attemptedZ;
player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation());
break;
}
}
}
String dir = "north";
//CHOOSES A RANDOM DIRECTION
for(int i = 0; i < 1000; i++){
double randomDirection = Math.random();
if (randomDirection < 0.25){
if(northUsed){
northUsed = true;
dir = "north";
break;
}
}else if(randomDirection < 0.50){
if(eastUsed){
eastUsed = true;
dir = "east";
break;
}
}else if(randomDirection < 0.75){
if(southUsed){
southUsed = true;
dir = "south";
break;
}
}else{
if(westUsed){
westUsed = true;
dir = "west";
break;
}
}
}
//TELEPORT - teleports player to the conflict point
switch(dir){
case "north":
northUsed = false;
player.teleport(world.getHighestBlockAt(conflictX, conflictZ - conflictRadius).getLocation());
break;
case "east":
eastUsed = false;
player.teleport(world.getHighestBlockAt(conflictX + conflictRadius, conflictZ).getLocation());
break;
case "south":
southUsed = false;
player.teleport(world.getHighestBlockAt(conflictX, conflictZ + conflictRadius).getLocation());
break;
case "west":
westUsed = false;
player.teleport(world.getHighestBlockAt(conflictX - conflictRadius, conflictZ).getLocation());
break;
default:
player.teleport(world.getHighestBlockAt(conflictX, conflictZ).getLocation());
break;
}
}
//Randomly teleports a player, into the hardcore world
public void rtp(Player player, World world, Location minLocation, Location maxLocation){
//INIT - xDifference, xAverage
int xdifference = minLocation.getBlockX() - maxLocation.getBlockX();
int xAverage = (int) Math.floor(minLocation.getBlockX() + maxLocation.getBlockX() / 2);
//INIT - zDifference, zAverage
int zdifference = minLocation.getBlockX() - maxLocation.getBlockY();
int zAverage = (int) Math.floor(minLocation.getBlockZ() + maxLocation.getBlockZ());
//TELEPORTS - Tries 20 times to find a location
for(int i = 0; i < 20; i ++){
//INIT - attemptedX, attemptedZ
int attemptedX = (int) Math.floor((Math.random()-0.5)*xdifference) + xAverage;
int attemptedZ = (int) Math.floor((Math.random()-0.5)*zdifference) + zAverage;
//CHECKS - if ground is safe
boolean groundisSafe = world.getHighestBlockAt(attemptedX, attemptedZ).getType() != Material.WATER;
if (groundisSafe){
player.teleport(world.getHighestBlockAt(attemptedX, attemptedZ).getLocation());
return;
}
//player.teleport(arg0)
}
}
}

View file

@ -1,68 +0,0 @@
package alisolarflare.listeners;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
public class ConflictCompassCraftingListener implements Listener{
@EventHandler
public boolean onConflictCompassCraft(CraftItemEvent event){
//SANITATION - HARDCORE
if(event.getWhoClicked().getWorld().getName() != "hardcore"){
return false;
}
//INIT - targetItem
ItemStack targetItem = event.getRecipe().getResult();
//SANITATION - NOT COMPASS
if(targetItem.getType() != Material.COMPASS){
return false;
}
event.setCancelled(true);
//GIVE - chainmail chestplate
event.getWhoClicked().getInventory().addItem(generateConflictCompass(event.getWhoClicked()));
//PLAY - cave sound
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0);
return false;
}
private ItemStack generateConflictCompass(HumanEntity crafter) {
ItemStack conflictCompass = new ItemStack(Material.COMPASS);
conflictCompass.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
List<String> loreString = new ArrayList<String>();
loreString.add("The needle is tipped with the scent of");
loreString.add(nearestPlayerName(crafter));
conflictCompass.getItemMeta().setLore(loreString);
return null;
}
private String nearestPlayerName(HumanEntity crafter) {
Player nearestPlayer = null;
for(Player player: crafter.getWorld().getPlayers()){
if (player.getUniqueId() == crafter.getUniqueId()){
//SKIP CODE
}if (nearestPlayer == null){
nearestPlayer = player;
}else if (nearestPlayer.getLocation().distance(crafter.getLocation()) > player.getLocation().distance(crafter.getLocation())){
nearestPlayer = player;
}
}
if(nearestPlayer == null){
return "METAL";
}
return nearestPlayer.toString();
}
}

View file

@ -1,51 +0,0 @@
package alisolarflare.listeners;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
public class DiamondArmorBlocker implements Listener{
public static List<Material> blockedItems = Arrays.asList(Material.DIAMOND_BOOTS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_HELMET);
@EventHandler
public boolean onArmorSmith(CraftItemEvent event){
//SANITATION - hardcore
if(event.getWhoClicked().getWorld().getName() != "hardcore"){
return false;
}
//INIT - inventory, targetItem
ItemStack targetItem = event.getRecipe().getResult();
//REPLACE - Diamond Chestplate > Chainmail Chestplate
if (blockedItems.contains(targetItem.getType())){
event.setCancelled(true);
//GIVE - chainmail chestplate
event.getWhoClicked().getInventory().addItem(failArmor(targetItem.getType()));
//PLAY - cave sound
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.AMBIENT_CAVE,0,0);
event.getWhoClicked().getWorld().playSound(event.getWhoClicked().getLocation(), Sound.ENTITY_ITEM_BREAK,0,0);
}
return false;
}
public ItemStack failArmor(Material material){
ItemStack failArmor = new ItemStack(material);
failArmor.addEnchantment(Enchantment.THORNS, 1);
//INIT - Chainmail's lore
List<String> loreString = new ArrayList<String>();
loreString.add("This world is forever dangerous.");
loreString.add("There is no protection here.");
failArmor.getItemMeta().setLore(loreString);
return failArmor;
}
}

View file

@ -1,91 +0,0 @@
package iie;
import java.util.Objects;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
public class DeathListener implements Listener {
HelloWorldPlugin plugin;
public DeathListener(HelloWorldPlugin plugin){
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onHardcoreDeath(PlayerDeathEvent deathEvent){
String timeString = String.valueOf(System.currentTimeMillis());
Player player = deathEvent.getEntity();
String playerString = (String) player.getName();
Location location = player.getLocation();
String worldString = (String) location.getWorld().getName();
//player.sendMessage(timeString);
//player.sendMessage(playerString);
//player.sendMessage(worldString);
if (Objects.equals(worldString, "hardcore")){
HelloWorldPlugin.deathMap.put(playerString, timeString);
if (HelloWorldPlugin.hardcoreTimeDead == null){
player.sendMessage("Objective hardcoreTimeDead was null");
}else if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) == null){
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0);
player.sendMessage("Score for hardcoreTimeDead was null, set to " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()));
}
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore((int) (System.currentTimeMillis()/1000));
//player.sendMessage(HelloWorldPlugin.deathMap.toString());
//player.sendMessage("Key saved: " + playerString);
//player.sendMessage("Data saved: " + HelloWorldPlugin.deathMap.get(playerString));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent JoinEvent){
Player player = JoinEvent.getPlayer();
String playerString = (String) player.getName();
player.sendMessage(playerString + " has joined");
if (HelloWorldPlugin.hardcoreTimeDead.getScore(playerString) != null){
HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000));
player.sendMessage("getScore(playerString) was not null");
}else{
HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(0);
HelloWorldPlugin.deathMap.put(playerString, String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()));
}
//try{
// HelloWorldPlugin.hardcoreTimeDead.getScore(playerString);
// player.sendMessage("try");
//}catch(IllegalArgumentException e){
// HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).setScore(1);
// player.sendMessage("catch");
//}finally{
// HelloWorldPlugin.deathMap.put(playerString, String.valueOf((HelloWorldPlugin.hardcoreTimeDead.getScore(playerString).getScore()) * 1000));
// player.sendMessage("finally");
//}
}
}

View file

@ -1,75 +0,0 @@
package iie;
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;
public class HelloWorld implements CommandExecutor {
HelloWorldPlugin plugin;
public HelloWorld(HelloWorldPlugin plugin){
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
if (sender instanceof Player){
long currentTime = System.currentTimeMillis();
String playername = sender.getName();
long deathTime = 0;
//sender.sendMessage("Playername: " + playername);
//sender.sendMessage("Data Imported: " + HelloWorldPlugin.deathMap.get(playername));
if (HelloWorldPlugin.deathMap.get(playername) != null){
deathTime = Long.parseLong(HelloWorldPlugin.deathMap.get(playername));
//sender.sendMessage("DeathTime: " + deathTime);
}else{
sender.sendMessage("You have never died in hardcore");
Player player = (Player) sender;
World hardcoreWorld = player.getServer().getWorld("hardcore");
Location location = new Location(hardcoreWorld, 1280, 71, -179);
player.teleport(location);
}
if (currentTime - deathTime >= 86400000 && deathTime != 0){
sender.sendMessage("You died " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours ago. Ready to give it another shot?");
Player player = (Player) sender;
World hardcoreWorld = player.getServer().getWorld("hardcore");
Location location = new Location(hardcoreWorld, 1280, 71, -179);
player.teleport(location);
}else if(deathTime == 0){
sender.sendMessage("good luck");
}else{
sender.sendMessage("you are dead for the next " + (86400000 - (currentTime - deathTime) ) /3600000 + " hours");
}
sender.sendMessage("Your hardcoreTimeDead score is " + String.valueOf(HelloWorldPlugin.hardcoreTimeDead.getScore(playername).getScore()));
}else{
sender.sendMessage("You must be a player to use this command!");
}
return false;
}
}

View file

@ -1,54 +0,0 @@
package iie;
import java.util.AbstractMap;
import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class HelloWorldPlugin extends JavaPlugin {
public static Scoreboard board;
public static Objective hardcoreTimeDead;
public static AbstractMap<String,String> deathMap = new HashMap<String,String>();
public void onEnable(){
try{
board.getObjective("hardcoreTimeDead");
}catch (NullPointerException e){
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
}finally{
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
}
board = Bukkit.getServer().getScoreboardManager().getMainScoreboard();
if (board.getObjective("hardcoreTimeDead") != null){
hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
}else{
hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
}
registerCommands();
getServer().getPluginManager().registerEvents(new DeathListener(this), this);
}
public void registerCommands(){
getCommand("HelloWorld").setExecutor(new HelloWorld(this));
}
}
//try{
// board.getObjective("hardcoreTimeDead");
//}catch (IllegalArgumentException e){
// hardcoreTimeDead = board.registerNewObjective("hardcoreTimeDead", "dummy");
//}finally{
// hardcoreTimeDead = board.getObjective("hardcoreTimeDead");
//}

View file

@ -0,0 +1,81 @@
package iie;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class InventoryStringDeSerializer {
public static String InventoryToString (Inventory invInventory){
String serialization = invInventory.getSize() + ";";
for (int i = 0; i < invInventory.getSize(); i++){
ItemStack is = invInventory.getItem(i);
if (is != null){
String serializedItemStack = new String();
String isType = String.valueOf(is.getType().getId());
serializedItemStack += "t@" + isType;
if (is.getDurability() != 0){
String isDurability = String.valueOf(is.getDurability());
serializedItemStack += ":d@" + isDurability;
}
if (is.getAmount() != 1){
String isAmount = String.valueOf(is.getAmount());
serializedItemStack += ":a@" + isAmount;
}
Map<Enchantment,Integer> isEnch = is.getEnchantments();
if (isEnch.size() > 0){
for (Entry<Enchantment,Integer> ench : isEnch.entrySet()){
serializedItemStack += ":e@" + ench.getKey().getId() + "@" + ench.getValue();
}
}
serialization += i + "#" + serializedItemStack + ";";
}
}
return serialization;
}
public static Inventory StringToInventory (String invString){
String[] serializedBlocks = invString.split(";");
String invInfo = serializedBlocks[0];
Inventory deserializedInventory = Bukkit.getServer().createInventory(null, Integer.valueOf(invInfo));
for (int i = 1; i < serializedBlocks.length; i++){
String[] serializedBlock = serializedBlocks[i].split("#");
int stackPosition = Integer.valueOf(serializedBlock[0]);
if (stackPosition >= deserializedInventory.getSize()){
continue;
}
ItemStack is = null;
Boolean createdItemStack = false;
String[] serializedItemStack = serializedBlock[1].split(":");
for (String itemInfo : serializedItemStack){
String[] itemAttribute = itemInfo.split("@");
if (itemAttribute[0].equals("t")){
is = new ItemStack(Material.getMaterial(Integer.valueOf(itemAttribute[1])));
createdItemStack = true;
}else if(itemAttribute[0].equals("d") && createdItemStack){
is.setDurability(Short.valueOf(itemAttribute[1]));
}else if(itemAttribute[0].equals("a") && createdItemStack){
is.setAmount(Integer.valueOf(itemAttribute[1]));
}else if(itemAttribute[0].equals("e") && createdItemStack){
is.addEnchantment(Enchantment.getById(Integer.valueOf(itemAttribute[1])), Integer.valueOf(itemAttribute[2]));
}
}
deserializedInventory.setItem(stackPosition, is);
}
return deserializedInventory;
}
}

View file

@ -0,0 +1,43 @@
package iie;
import java.io.File;
import org.bukkit.plugin.java.JavaPlugin;
public class PerWorldInventoryPlugin extends JavaPlugin {
public void onEnable(){
getServer().getPluginManager().registerEvents(new WorldChangeListener(this), this);
registerCommands();
createConfig();
}
public void registerCommands(){
getCommand("soundtest").setExecutor(new SoundTest (this));
}
private void createConfig(){
try {
if (!getDataFolder().exists())
getDataFolder().mkdirs();
File file = new File(getDataFolder(), "config.yml");
if (!file.exists()){
getLogger().info("Config.yml not found, creating!");
saveDefaultConfig();
}else{
getLogger().info("Config.yml found, loading!");
}
}catch (Exception e) {
e.printStackTrace();
}
}
}

26
src/iie/SoundTest.java Normal file
View file

@ -0,0 +1,26 @@
package iie;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class SoundTest implements CommandExecutor{
PerWorldInventoryPlugin plugin;
public SoundTest(PerWorldInventoryPlugin plugin){
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command label, String command, String[] args) {
Player player = (Player) sender;
player.getWorld().playSound(player.getLocation(), Sound.AMBIENT_CAVE,1F,1F);
return false;
}
}

View file

@ -0,0 +1,57 @@
package iie;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.inventory.Inventory;
public class WorldChangeListener implements Listener {
PerWorldInventoryPlugin plugin;
public WorldChangeListener(PerWorldInventoryPlugin plugin){
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldChangeListener(PlayerChangedWorldEvent event){
Player player = event.getPlayer();
String playername = player.getName();
World worldTo = player.getWorld();
World worldFrom = event.getFrom();
String worldToName = worldTo.getName();
String worldFromName = worldFrom.getName();
String pathTo = worldToName + "." + playername + ".";
String pathFrom = worldFromName + "." + playername + ".";
Inventory invInventory;
String invString;
invInventory = player.getInventory();
invString = InventoryStringDeSerializer.InventoryToString(invInventory);
plugin.getConfig().set(pathFrom + "inventory",invString);
plugin.saveConfig();
player.sendMessage("you changed worlds");
player.sendMessage(invString);
invString = (String) plugin.getConfig().get(pathTo + "inventory");
player.sendMessage(invString);
invInventory = InventoryStringDeSerializer.StringToInventory(invString);
player.sendMessage(invInventory.toString());
player.getInventory().setContents(invInventory.getContents());
}
}