Update Outdated Code

This commit is contained in:
Ghoti 2019-01-23 18:04:12 -06:00
parent 5d889b0e77
commit 6dcaacee49
13 changed files with 342 additions and 341 deletions

View File

@ -4,7 +4,7 @@
<groupId>me.ghotimayo</groupId> <groupId>me.ghotimayo</groupId>
<artifactId>ClassicSwords</artifactId> <artifactId>ClassicSwords</artifactId>
<name>ClassicSwords</name> <name>ClassicSwords</name>
<version>BETA-0.1</version> <version>BETA-1.0</version>
<description>Old combat for new minecraft</description> <description>Old combat for new minecraft</description>
<build> <build>
<plugins> <plugins>
@ -46,7 +46,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version> <version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
@ -58,13 +58,13 @@
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version> <version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version> <version>1.13.2-R0.1-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>me.ghotimayo</groupId> <groupId>me.ghotimayo</groupId>
<artifactId>ClassicSwords</artifactId> <artifactId>ClassicSwords</artifactId>
<version>BETA-0.1</version> <version>BETA-1.0</version>
<name>ClassicSwords</name> <name>ClassicSwords</name>
<description>Old combat for new minecraft</description> <description>Old combat for new minecraft</description>
<properties> <properties>

View File

@ -1,10 +1,6 @@
package com.fpghoti.classicswords; package com.fpghoti.classicswords;
import java.util.ArrayList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,11 +9,11 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.fpghoti.classicswords.commands.CSword; import com.fpghoti.classicswords.commands.CSwordCommand;
import com.fpghoti.classicswords.event.BlockingEvent; import com.fpghoti.classicswords.event.BlockingListener;
import com.fpghoti.classicswords.event.InventoryEvent; import com.fpghoti.classicswords.event.InventoryListener;
import com.fpghoti.classicswords.event.RegenEvent; import com.fpghoti.classicswords.event.RegenListener;
import com.fpghoti.classicswords.event.SwingEvent; import com.fpghoti.classicswords.event.SwingListener;
import com.fpghoti.classicswords.item.CItemType; import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword; import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.item.SetAttributes; import com.fpghoti.classicswords.item.SetAttributes;
@ -30,7 +26,7 @@ public class ClassicSwordsMain extends JavaPlugin{
plugin = this; plugin = this;
SetAttributes.defineSwords(); SetAttributes.defineSwords();
registerEvents(); registerEvents();
getCommand("CSword").setExecutor(new CSword(this)); getCommand("CSword").setExecutor(new CSwordCommand());
registerConfig(); registerConfig();
messageSet(); messageSet();
startItemCheck(); startItemCheck();
@ -61,11 +57,11 @@ public class ClassicSwordsMain extends JavaPlugin{
} }
public void registerEvents(){ public void registerEvents(){
PluginManager pm = getServer().getPluginManager(); PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new SwingEvent(this), this); pm.registerEvents(new SwingListener(this), this);
InventoryEvent ie = new InventoryEvent(this); InventoryListener ie = new InventoryListener();
pm.registerEvents(ie, this); pm.registerEvents(ie, this);
pm.registerEvents(new BlockingEvent(this), this); pm.registerEvents(new BlockingListener(), this);
pm.registerEvents(new RegenEvent(this), this); pm.registerEvents(new RegenListener(this), this);
} }
FileConfiguration config = this.getConfig(); FileConfiguration config = this.getConfig();

View File

@ -6,16 +6,9 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.fpghoti.classicswords.ClassicSwordsMain; import com.fpghoti.classicswords.item.CItemManager;
import com.fpghoti.classicswords.item.CItem;
public class CSword implements CommandExecutor{ public class CSwordCommand implements CommandExecutor{
private ClassicSwordsMain plugin;
public CSword(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args){ public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
if(label.equalsIgnoreCase("csword")){ if(label.equalsIgnoreCase("csword")){
@ -23,15 +16,15 @@ public class CSword implements CommandExecutor{
Player p = (Player) sender; Player p = (Player) sender;
if(args[0] != null){ if(args[0] != null){
if(args[0].equalsIgnoreCase("wood")){ if(args[0].equalsIgnoreCase("wood")){
CItem.givecWoodSword(p, false); CItemManager.givecWoodSword(p, false);
}else if(args[0].equalsIgnoreCase("stone")){ }else if(args[0].equalsIgnoreCase("stone")){
CItem.givecStoneSword(p, false); CItemManager.givecStoneSword(p, false);
}else if(args[0].equalsIgnoreCase("iron")){ }else if(args[0].equalsIgnoreCase("iron")){
CItem.givecIronSword(p, false); CItemManager.givecIronSword(p, false);
}else if(args[0].equalsIgnoreCase("gold")){ }else if(args[0].equalsIgnoreCase("gold")){
CItem.givecGoldSword(p, false); CItemManager.givecGoldSword(p, false);
}else if(args[0].equalsIgnoreCase("diamond")){ }else if(args[0].equalsIgnoreCase("diamond")){
CItem.givecDiamondSword(p, false); CItemManager.givecDiamondSword(p, false);
}else{ }else{
p.sendMessage(ChatColor.RED + "That is not a valid cSword type!"); p.sendMessage(ChatColor.RED + "That is not a valid cSword type!");
} }

View File

@ -1,5 +1,6 @@
package com.fpghoti.classicswords.event; package com.fpghoti.classicswords.event;
import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -12,13 +13,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
import com.fpghoti.classicswords.ClassicSwordsMain; import com.fpghoti.classicswords.ClassicSwordsMain;
public class BlockingEvent implements Listener{ public class BlockingListener implements Listener{
private ClassicSwordsMain plugin;
public BlockingEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -31,6 +26,7 @@ public class BlockingEvent implements Listener{
if(newdamage < 0) { if(newdamage < 0) {
newdamage = 0; newdamage = 0;
} }
if(event.getDamage(DamageModifier.BLOCKING) >= 0){ if(event.getDamage(DamageModifier.BLOCKING) >= 0){
return; return;
} }
@ -38,9 +34,29 @@ public class BlockingEvent implements Listener{
if(event.getFinalDamage() >= newdamage) { if(event.getFinalDamage() >= newdamage) {
event.setDamage(DamageModifier.BLOCKING, newdamage * -1); event.setDamage(DamageModifier.BLOCKING, newdamage * -1);
} }
} }
} }
} }
//For future use
@SuppressWarnings("unused")
private boolean hitShield(Location attacker, Location victim) {
double attackerPitch = Math.toRadians(attacker.getPitch());
double attackerYaw = Math.toRadians(attacker.getYaw());
double attackerX = -Math.cos(attackerPitch) * Math.sin(attackerYaw);
double attackerY = -Math.sin(attackerPitch);
double attackerZ = Math.cos(attackerPitch) * Math.cos(attackerYaw);
double victimPitch = Math.toRadians(victim.getPitch());
double victimYaw = Math.toRadians(victim.getYaw());
double victimX = -Math.cos(victimPitch) * Math.sin(victimYaw);
double victimY = -Math.sin(victimPitch);
double victimZ = Math.cos(victimPitch) * Math.cos(victimYaw);
return (victimX * attackerX + victimY * attackerY + victimZ * attackerZ) < 0.6D;
}
} }

View File

@ -14,18 +14,11 @@ import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.item.CItemType; import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword; import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.util.Storage; import com.fpghoti.classicswords.util.Storage;
public class InventoryEvent implements Listener{ public class InventoryListener implements Listener{
private ClassicSwordsMain plugin;
public InventoryEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@EventHandler @EventHandler
public void onInvOpen(InventoryOpenEvent event){ public void onInvOpen(InventoryOpenEvent event){

View File

@ -1,12 +1,7 @@
package com.fpghoti.classicswords.event; package com.fpghoti.classicswords.event;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -17,11 +12,11 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
import com.fpghoti.classicswords.ClassicSwordsMain; import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.util.Storage; import com.fpghoti.classicswords.util.Storage;
public class RegenEvent implements Listener{ public class RegenListener implements Listener{
private ClassicSwordsMain plugin; private ClassicSwordsMain plugin;
public RegenEvent(ClassicSwordsMain plugin) { public RegenListener(ClassicSwordsMain plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -1,12 +1,8 @@
package com.fpghoti.classicswords.event; package com.fpghoti.classicswords.event;
import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -17,19 +13,17 @@ import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import com.fpghoti.classicswords.ClassicSwordsMain; import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.item.CItem;
import com.fpghoti.classicswords.item.CItemType; import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword; import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.util.Storage; import com.fpghoti.classicswords.util.Storage;
public class SwingEvent implements Listener{ public class SwingListener implements Listener{
private ClassicSwordsMain plugin; private ClassicSwordsMain plugin;
public SwingEvent(ClassicSwordsMain plugin) { public SwingListener(ClassicSwordsMain plugin) {
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -1,269 +0,0 @@
package com.fpghoti.classicswords.item;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagDouble;
import net.minecraft.server.v1_13_R2.NBTTagInt;
import net.minecraft.server.v1_13_R2.NBTTagList;
import net.minecraft.server.v1_13_R2.NBTTagString;
public class CItem {
public static void givecDiamondSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1, (short)1);
ItemMeta meta = csword.getItemMeta();
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Diamond Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(7));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecWoodSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1, (short)2);
ItemMeta meta = csword.getItemMeta();
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Wood Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(4));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecStoneSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1, (short)3);
ItemMeta meta = csword.getItemMeta();
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Stone Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(5));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecIronSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1, (short)4);
ItemMeta meta = csword.getItemMeta();
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Iron Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(6));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecGoldSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1, (short)5);
ItemMeta meta = csword.getItemMeta();
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Gold Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(4));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
}

View File

@ -0,0 +1,275 @@
package com.fpghoti.classicswords.item;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import net.md_5.bungee.api.ChatColor;
import net.minecraft.server.v1_13_R2.NBTTagCompound;
import net.minecraft.server.v1_13_R2.NBTTagDouble;
import net.minecraft.server.v1_13_R2.NBTTagInt;
import net.minecraft.server.v1_13_R2.NBTTagList;
import net.minecraft.server.v1_13_R2.NBTTagString;
public class CItemManager {
public static void givecDiamondSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(1);
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Diamond Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(7));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecWoodSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(2);
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Wood Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(4));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecStoneSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(3);
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Stone Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(5));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecIronSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(4);
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Iron Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(6));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
public static void givecGoldSword(Player p, Boolean hold){
ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(5);
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName("Classic Gold Sword");
csword.setItemMeta(meta);
net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = new NBTTagCompound();
damage.set("AttributeName", new NBTTagString("generic.attackDamage"));
damage.set("Name", new NBTTagString("generic.attackDamage"));
damage.set("Amount", new NBTTagInt(4));
damage.set("Operation", new NBTTagInt(0));
damage.set("UUIDLeast", new NBTTagInt(894654));
damage.set("UUIDMost", new NBTTagInt(2872));
damage.set("Slot", new NBTTagString("mainhand"));
NBTTagCompound atspeed = new NBTTagCompound();
atspeed.set("AttributeName", new NBTTagString("generic.attackSpeed"));
atspeed.set("Name", new NBTTagString("generic.attackSpeed"));
atspeed.set("Amount", new NBTTagDouble(1021.6));
atspeed.set("Operation", new NBTTagInt(0));
atspeed.set("UUIDLeast", new NBTTagInt(894654));
atspeed.set("UUIDMost", new NBTTagInt(2872));
atspeed.set("Slot", new NBTTagString("mainhand"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(hold){
p.getInventory().setItemInMainHand(csword);
}else{
p.sendMessage(ChatColor.AQUA + "Spawning in a cSword...");
p.getInventory().addItem(csword);
}
}
}

View File

@ -1,7 +1,6 @@
package com.fpghoti.classicswords.item; package com.fpghoti.classicswords.item;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.fpghoti.classicswords.util.Storage; import com.fpghoti.classicswords.util.Storage;

View File

@ -1,7 +1,6 @@
package com.fpghoti.classicswords.item; package com.fpghoti.classicswords.item;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -12,6 +11,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import com.fpghoti.classicswords.item.CItemType.SwordType; import com.fpghoti.classicswords.item.CItemType.SwordType;
@ -29,8 +29,11 @@ public class ClassicSword {
String name; String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordModel(type)); ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta(); ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(CItemType.getSwordModel(type));
if(old.hasItemMeta()) { if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta(); ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) { if(ometa.hasDisplayName()) {
@ -66,7 +69,9 @@ public class ClassicSword {
NBTTagCompound cstag = new NBTTagCompound(); NBTTagCompound cstag = new NBTTagCompound();
int dur = old.getType().getMaxDurability() - old.getDurability(); //int dur = old.getType().getMaxDurability() - old.getDurability();
int dur = old.getType().getMaxDurability() - ((Damageable)old.getItemMeta()).getDamage();
cstag.set("Durability", new NBTTagInt(dur)); cstag.set("Durability", new NBTTagInt(dur));
cstag.set("Type", new NBTTagString(CItemType.getShortName(type))); cstag.set("Type", new NBTTagString(CItemType.getShortName(type)));
@ -88,9 +93,11 @@ public class ClassicSword {
if(isCShield(old)) { if(isCShield(old)) {
String name; String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordBlockModel(type)); ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta(); ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(CItemType.getSwordBlockModel(type));
if(old.hasItemMeta()) { if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta(); ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) { if(ometa.hasDisplayName()) {
@ -157,9 +164,11 @@ public class ClassicSword {
String name; String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordModel(type)); ItemStack csword = new ItemStack(Material.SHIELD, 1);
ItemMeta meta = csword.getItemMeta(); ItemMeta meta = csword.getItemMeta();
((Damageable)meta).setDamage(CItemType.getSwordModel(type));
if(old.hasItemMeta()) { if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta(); ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) { if(ometa.hasDisplayName()) {
@ -268,7 +277,8 @@ public class ClassicSword {
nmsStack.setTag(compound); nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack); csword = CraftItemStack.asBukkitCopy(nmsStack);
csword.setDurability((short)(csword.getType().getMaxDurability() - (short)((int)getCShieldDurability(old)))); //csword.setDurability((short)(csword.getType().getMaxDurability() - (short)((int)getCShieldDurability(old))));
((Damageable)csword.getItemMeta()).setDamage(csword.getType().getMaxDurability() - ((int)getCShieldDurability(old)));
return csword; return csword;
} }

View File

@ -1,6 +1,5 @@
package com.fpghoti.classicswords.util; package com.fpghoti.classicswords.util;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;