Initial Commit

This commit is contained in:
Ghoti 2019-01-01 21:22:38 -06:00
commit 6fe13d6a4b
20 changed files with 2047 additions and 0 deletions

15
.classpath Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
bin/

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ClassicSwords</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,13 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.ghotimayo</groupId>
<artifactId>ClassicSwords</artifactId>
<name>ClassicSwords</name>
<version>BETA-0.1</version>
<description>Old combat for new minecraft</description>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<source>1.8</source>
<artifactSet>
<includes>
<include>me.ghotimayo*:*</include>
<include>de.tr7zw*:*</include>
</includes>
</artifactSet>
<relocations />
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>bungeecord-chat</artifactId>
<groupId>net.md-5</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
<version>4.3.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

80
pom.xml Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.ghotimayo</groupId>
<artifactId>ClassicSwords</artifactId>
<version>BETA-0.1</version>
<name>ClassicSwords</name>
<description>Old combat for new minecraft</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-parent</artifactId>
<version>1.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
<version>4.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<source>1.8</source>
<artifactSet>
<includes>
<include>me.ghotimayo*:*</include>
<include>de.tr7zw*:*</include>
</includes>
</artifactSet>
<relocations />
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,203 @@
package com.fpghoti.classicswords;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.fpghoti.classicswords.commands.CSword;
import com.fpghoti.classicswords.event.BlockingEvent;
import com.fpghoti.classicswords.event.InventoryEvent;
import com.fpghoti.classicswords.event.RegenEvent;
import com.fpghoti.classicswords.event.SwingEvent;
import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.item.SetAttributes;
import com.fpghoti.classicswords.util.Storage;
public class ClassicSwordsMain extends JavaPlugin{
private static ClassicSwordsMain plugin;
public void onEnable() {
plugin = this;
SetAttributes.defineSwords();
registerEvents();
getCommand("CSword").setExecutor(new CSword(this));
registerConfig();
messageSet();
startItemCheck();
//startBlockCheck();
}
public void onDisable() {
plugin = null;
}
public static Plugin getPlugin()
{
return plugin;
}
public static ClassicSwordsMain getMain(){
return plugin;
}
private void registerConfig() {
this.getConfig().options().copyDefaults(true);
config.options().copyHeader(true);
saveConfig();
}
public void registerEvents(){
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new SwingEvent(this), this);
InventoryEvent ie = new InventoryEvent(this);
pm.registerEvents(ie, this);
pm.registerEvents(new BlockingEvent(this), this);
pm.registerEvents(new RegenEvent(this), this);
}
FileConfiguration config = this.getConfig();
public void messageSet(){
if (config.get("Options")==null){
config.createSection("Options.ReplaceNormalSwords");
config.set("Options.ReplaceNormalSwords", false);
Storage.bools.put("ReplaceNormalSwords", config.getBoolean("Options.ReplaceNormalSwords"));
}
this.saveConfig();
}
public void startItemCheck() {
new BukkitRunnable(){
public void run() {
for(Player p : Bukkit.getOnlinePlayers()) {
if(p.getInventory().getItemInMainHand() != null) {
// if(ClassicSword.isCShield(p.getInventory().getItemInMainHand())) {
// if(p.isHandRaised()) {
// System.out.println("B");
// Storage.blockers.add(p);
// runBlock(p);
// }
// }
if(CItemType.isSword(p.getInventory().getItemInMainHand().getType())){
if(!ClassicSword.hasOpenInv(p)) {
if(!ClassicSword.isBlocking(p) && !Storage.swingers.contains(p) && ClassicSword.isCBlockShield(p.getInventory().getItemInMainHand())) {
p.getInventory().setItemInMainHand(ClassicSword.blockToShield(p.getInventory().getItemInMainHand(), CItemType.getType(ClassicSword.getCShieldShortName(p.getInventory().getItemInMainHand()))));
}
ItemStack newitem = ClassicSword.toShield(p.getInventory().getItemInMainHand(), CItemType.getSwordType(p.getInventory().getItemInMainHand().getType()));
Integer dur = ClassicSword.getCShieldDurability(newitem);
p.getInventory().setItemInMainHand(newitem);
ClassicSword.sendActionbar(p, "§eDurability: " + dur);
}
}
// if(p.isHandRaised() && Storage.swingers.contains(p) && ClassicSword.isCShield(p.getInventory().getItemInMainHand())) {
// p.getInventory().setItemInMainHand(ClassicSword.toBlockShield(p.getInventory().getItemInMainHand(), CItemType.getType(ClassicSword.getCShieldShortName(p.getInventory().getItemInMainHand()))));
// p.playSound(p.getLocation(), Sound.ENTITY_IRONGOLEM_STEP, 10.0F, 1.0F);
// ClassicSword.sendActionbar(p, "§aBlock hit!");
// Storage.swingers.remove(p);
//
// blockToShieldTimer(p);
// }
}
}
}
// }.runTaskTimerAsynchronously(this, 1*20, 1*20);
}.runTaskTimerAsynchronously(this, 1*1, 1*1);
}
public static void runBlockHit(Player p) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Storage.swingers.remove(p);
}
}, 10L);
}
public static void runKB(Player p) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Storage.kb.remove(p);
}
}, 20L);
}
public static void runBlock(Player p) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Storage.blockers.remove(p);
}
}, 20L);
}
public static void runRecent(Player p, Player damaged) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Storage.recent.remove(p);
Storage.recenthealth.remove(damaged);
}
}, 20L);
}
public static void blockToShieldTimer(Player p) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
if(!ClassicSword.hasOpenInv(p) && !Storage.swingers.contains(p)) {
ClassicSword.blockToShieldInv(p.getInventory());
}
}
}, 10L);
}
public static void streakTimer(Player p) {
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Storage.great.remove(p);
Storage.perfect.remove(p);
}
}, 80L);
}
// public void startBlockCheck() {
// new BukkitRunnable(){
// public void run() {
// Storage.blockers.clear();
// for(Player p : Bukkit.getOnlinePlayers()) {
// if(p.getInventory().getItemInMainHand() != null && p.isBlocking()) {
// Storage.blockers.add(p);
// }
// }
//
// }
// // }.runTaskTimerAsynchronously(this, 1*20, 1*20);
// }.runTaskTimerAsynchronously(this, 1*1, 1*1);
// }
}

View File

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

View File

@ -0,0 +1,46 @@
package com.fpghoti.classicswords.event;
import org.bukkit.entity.Entity;
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.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
import org.bukkit.event.inventory.InventoryOpenEvent;
import com.fpghoti.classicswords.ClassicSwordsMain;
public class BlockingEvent implements Listener{
private ClassicSwordsMain plugin;
public BlockingEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent event){
if(event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity();
if(p.isHandRaised() || p.isBlocking()){
double newdamage = event.getDamage() * 0.5;
if(newdamage < 0) {
newdamage = 0;
}
if(event.getDamage(DamageModifier.BLOCKING) >= 0){
return;
}
event.setDamage(DamageModifier.BLOCKING, 0);
if(event.getFinalDamage() >= newdamage) {
event.setDamage(DamageModifier.BLOCKING, newdamage * -1);
}
}
}
}
}

View File

@ -0,0 +1,119 @@
package com.fpghoti.classicswords.event;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.util.Storage;
public class InventoryEvent implements Listener{
private ClassicSwordsMain plugin;
public InventoryEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@EventHandler
public void onInvOpen(InventoryOpenEvent event){
if(event.getPlayer() != null){
Storage.inInv.add((Player)event.getPlayer());
ClassicSword.toSwordInv(((Player)event.getPlayer()).getInventory());
}
}
@EventHandler
public void onInvClose(InventoryCloseEvent event){
if(event.getPlayer() != null){
Storage.inInv.remove((Player)event.getPlayer());
ClassicSword.toShieldInv(((Player)event.getPlayer()).getInventory());
ClassicSword.blockToShieldInv(((Player)event.getPlayer()).getInventory());
}
}
@EventHandler
public void onExp(PlayerExpChangeEvent event){
if(event.getPlayer() != null){
Player p = event.getPlayer();
if(ClassicSword.isCShield(p.getInventory().getItemInMainHand())) {
ItemStack csword = p.getInventory().getItemInMainHand();
if(csword.containsEnchantment(Enchantment.MENDING)) {
int max = CItemType.getMaxDurability(CItemType.getType(ClassicSword.getCShieldShortName(csword)));
int dur = ClassicSword.getCShieldDurability(csword);
int expnum = event.getAmount();
int pxpadd = 0;
if(dur != max) {
if(dur + expnum <= max) {
ClassicSword.setCShieldDurability(p, csword, dur + expnum);
event.setAmount(0);
}else if(dur + expnum > max){
pxpadd = (dur + expnum) - max;
ClassicSword.setCShieldDurability(p, csword, max);
event.setAmount(pxpadd);
}
}
}
}
}
}
@EventHandler
public void onInvClick(InventoryClickEvent event){
Player p = (Player) event.getWhoClicked();
if(event.getInventory() != null && p != null){
if(!event.isShiftClick()) {
ClassicSword.toSwordInv(p.getInventory());
}
}
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event){
handleDisconnect(event.getPlayer());
}
@EventHandler
public void onPlayerKick(PlayerKickEvent event){
handleDisconnect(event.getPlayer());
}
public static void handleDisconnect(Player p) {
Storage.inInv.remove(p);
}
@EventHandler
public void onItemClick(InventoryDragEvent event){
if(event.getClass() != null){
if(ClassicSword.isCShield(event.getCursor())) {
ItemStack newsword = ClassicSword.toSword(event.getCursor(), CItemType.getType(ClassicSword.getCShieldShortName(event.getCursor())));
event.setCursor(newsword);
}
}
}
@EventHandler
public void onHold(PlayerItemHeldEvent event){
if(event.getPlayer() != null && ClassicSword.isCShield(event.getPlayer().getInventory().getItem(event.getNewSlot()))){
Integer dur = ClassicSword.getCShieldDurability(event.getPlayer().getInventory().getItem(event.getNewSlot()));
ClassicSword.sendActionbar(event.getPlayer(), "§eDurability: " + dur);
}
}
}

View File

@ -0,0 +1,59 @@
package com.fpghoti.classicswords.event;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
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.EntityRegainHealthEvent;
import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.util.Storage;
public class RegenEvent implements Listener{
private ClassicSwordsMain plugin;
public RegenEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onRegen(EntityRegainHealthEvent event){
if(event.getEntityType() == EntityType.PLAYER || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
event.setCancelled(true);
Player p = (Player) event.getEntity();
double max = p.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
long time = System.currentTimeMillis() / 1000;
long last = Storage.regens.computeIfAbsent(p.getUniqueId(), id -> System.currentTimeMillis() / 1000);
if(time - last < (long) 3) {
return;
}
if(p.getHealth() < max){
double health = p.getHealth() + 1;
if(health < Math.min(0, max)){
health = Math.min(0, max);
}
if(health > Math.max(0, max)){
health = Math.max(0, max);
}
p.setHealth(health);
Storage.regens.put(p.getUniqueId(), time);
}
Bukkit.getScheduler().runTaskLater(plugin, () -> {
p.setExhaustion(p.getExhaustion() + 3);
}, 1L);
}
}
}

View File

@ -0,0 +1,242 @@
package com.fpghoti.classicswords.event;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import com.fpghoti.classicswords.ClassicSwordsMain;
import com.fpghoti.classicswords.item.CItem;
import com.fpghoti.classicswords.item.CItemType;
import com.fpghoti.classicswords.item.ClassicSword;
import com.fpghoti.classicswords.util.Storage;
public class SwingEvent implements Listener{
private ClassicSwordsMain plugin;
public SwingEvent(ClassicSwordsMain plugin) {
this.plugin = plugin;
}
@EventHandler
public void onSwingAtBlock(BlockDamageEvent event){
if(event.getBlock() != null){
if(event.getPlayer().getGameMode() != GameMode.CREATIVE && event.getInstaBreak()) {
Storage.instabreaks.add(event.getBlock().getType());
}
}
}
@EventHandler
public void onSwingAtBlock(BlockBreakEvent event){
if(event.getPlayer() != null){
Player p = event.getPlayer();
if(p.getInventory().getItemInMainHand() != null){
if(p.getInventory().getItemInMainHand().hasItemMeta()){
if(ClassicSword.isCShield(p.getInventory().getItemInMainHand())){
if(event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
event.setCancelled(true);
}else {
if(!Storage.instabreaks.contains(event.getBlock().getType())) {
ItemStack csword = p.getInventory().getItemInMainHand();
ClassicSword.damageCItem(p, csword, 2);
}
}
}
}
}
}
}
@EventHandler (priority=EventPriority.MONITOR)
public void onHitPlayer(EntityDamageByEntityEvent event){
if(event.getEntity() != null){
if(event.getDamager() instanceof Player) {
Player p = (Player)event.getDamager();
if(event.getEntity() instanceof Player) {
Player damaged = (Player) event.getEntity();
Storage.recent.put(p, damaged);
Storage.recenthealth.put(damaged, damaged.getHealth());
ClassicSwordsMain.runRecent(p, damaged);
}
// if(Storage.blockers.contains(p)) {
// System.out.println("B");
// p.playSound(p.getLocation(), Sound.BLOCK_NOTE_CHIME, 10.0F, 1.0F);
// }
ItemStack csword = p.getInventory().getItemInMainHand();
if(ClassicSword.isCShield(csword) && p.getGameMode() != GameMode.CREATIVE) {
ClassicSword.damageCItem(p, csword, 1);
}
}
}
}
@EventHandler
public void onHit(PlayerInteractEvent event){
if(event.getPlayer() != null){
Player p = event.getPlayer();
if((event.getAction() == Action.LEFT_CLICK_BLOCK) || (event.getAction() == Action.LEFT_CLICK_AIR)) {
if(ClassicSword.isCShield(event.getPlayer().getInventory().getItemInMainHand())) {
Storage.swingers.add(event.getPlayer());
ClassicSwordsMain.runBlockHit(event.getPlayer());
if(!ClassicSword.isBlocking(p)) {
ClassicSword.blockToShieldInv(p.getInventory());
}
}
}
if(event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if(Storage.swingers.contains(p) && ClassicSword.isCShield(p.getInventory().getItemInMainHand())) {
p.getInventory().setItemInMainHand(ClassicSword.toBlockShield(p.getInventory().getItemInMainHand(), CItemType.getType(ClassicSword.getCShieldShortName(p.getInventory().getItemInMainHand()))));
//p.playSound(p.getLocation(), Sound.ENTITY_IRONGOLEM_STEP, 10.0F, 1.0F);
p.playSound(p.getLocation(), Sound.ENTITY_IRONGOLEM_STEP, 10.0F, 1.0F);
if(Storage.recent.containsKey(p)) {
final Player damaged = Storage.recent.get(p);
Double health = Storage.recenthealth.get(damaged);
if(damaged != null && damaged.getHealth() != health && !Storage.kb.contains(damaged)) {
//damaged.getLocation().getY() + 0.5
//damaged.setVelocity(p.getEyeLocation().getDirection().setY(p.getEyeLocation().getDirection().getY() + 0.5).multiply(1.005));
double kb = p.getEyeLocation().getDirection().getY();
if(kb > damaged.getLocation().getDirection().getY()) {
kb = damaged.getLocation().getDirection().getY();
}
kb = kb + 0.5;
if(p.getLocation().getY() < damaged.getLocation().getY()) {
kb = kb/2;
damaged.setVelocity(p.getEyeLocation().getDirection().setY(kb).multiply(0.25));
}else {
//damaged.setVelocity(p.getEyeLocation().getDirection().setY(kb).multiply(1.001));
damaged.setVelocity(p.getEyeLocation().getDirection().setY(kb).multiply(0.75));
}
if(Storage.perfect.contains(p)) {
ClassicSword.sendActionbar(p, "§aPerfect!");
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
ClassicSword.sendActionbar(p, "§fPe§arfe§act!");
}
}, 3L);
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
ClassicSword.sendActionbar(p, "§aPe§frfe§act!");
}
}, 6L);
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
ClassicSword.sendActionbar(p, "§aPe§arfe§fct!");
}
}, 9L);
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
ClassicSword.sendActionbar(p, "§aPerfect!");
}
}, 12L);
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
ClassicSword.sendActionbar(p, "§a§lPerfect!");
}
}, 14L);
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BELL, 1.0F, 1.4F);
Storage.perfect.remove(p);
Storage.great.remove(p);
Storage.kb.add(damaged);
ClassicSwordsMain.runKB(damaged);
}else if(Storage.great.contains(p)) {
ClassicSword.sendActionbar(p, "§eGreat!");
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BELL, 1.0F, 1.2F);
Storage.perfect.add(p);
Storage.kb.add(damaged);
ClassicSwordsMain.runKB(damaged);
}else {
ClassicSword.sendActionbar(p, "§cGood!");
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BELL, 1.0F, 1.0F);
ClassicSwordsMain.streakTimer(p);
Storage.great.add(p);
Storage.kb.add(damaged);
ClassicSwordsMain.runKB(damaged);
}
}
Storage.recenthealth.remove(damaged);
Storage.recent.remove(p);
}
Storage.swingers.remove(p);
ClassicSwordsMain.blockToShieldTimer(p);
}else {
//ClassicSword.sendActionbar(p, "§aBlock hit!");
}
// System.out.println("A");
// Storage.blockers.add(p);
// ClassicSwordsMain.runBlock(p);
}else {
//ClassicSword.sendActionbar(p, "§aBlock hit!");
}
try{
ItemStack holding = p.getInventory().getItemInMainHand();
if(event.hasBlock()){
if(holding != null){
if(holding.hasItemMeta()){
if(ClassicSword.isCShield(holding)){
if(event.getAction().toString().contains("LEFT") ){
if(event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
event.setCancelled(true);
}
}
}
}
}
}
if(CItemType.isSword(holding.getType())) {
ClassicSword.toShield(holding, CItemType.getSwordType(holding.getType()));
}
}
catch(NullPointerException npex){
}
}
}
}

View File

@ -0,0 +1,269 @@
package com.fpghoti.classicswords.item;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_12_R1.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_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.NBTTagDouble;
import net.minecraft.server.v1_12_R1.NBTTagInt;
import net.minecraft.server.v1_12_R1.NBTTagList;
import net.minecraft.server.v1_12_R1.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_12_R1.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_12_R1.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_12_R1.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_12_R1.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_12_R1.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,216 @@
package com.fpghoti.classicswords.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import com.fpghoti.classicswords.util.Storage;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
public class CItemType {
public enum SwordType{
WOOD,
STONE,
IRON,
GOLD,
DIAMOND
}
public static NBTTagCompound getSwordType(SwordType type) {
switch (type) {
case WOOD:
return Storage.damagetag.get("wood");
case STONE:
return Storage.damagetag.get("stone");
case IRON:
return Storage.damagetag.get("iron");
case GOLD:
return Storage.damagetag.get("gold");
case DIAMOND:
return Storage.damagetag.get("diamond");
default:
return null;
}
}
public static short getSwordModel(SwordType type) {
switch (type) {
case WOOD:
return (short)2;
case STONE:
return (short)3;
case IRON:
return (short)4;
case GOLD:
return (short)5;
case DIAMOND:
return (short)1;
default:
return 2;
}
}
public static short getSwordBlockModel(SwordType type) {
switch (type) {
case WOOD:
return (short)7;
case STONE:
return (short)8;
case IRON:
return (short)9;
case GOLD:
return (short)10;
case DIAMOND:
return (short)6;
default:
return 7;
}
}
public static String getDefaultName(SwordType type) {
switch (type) {
case WOOD:
return "Wooden Sword";
case STONE:
return "Stone Sword";
case IRON:
return "Iron Sword";
case GOLD:
return "Golden Sword";
case DIAMOND:
return "Diamond Sword";
default:
return "ERROR";
}
}
public static String getShortName(SwordType type) {
switch (type) {
case WOOD:
return "wood";
case STONE:
return "stone";
case IRON:
return "iron";
case GOLD:
return "gold";
case DIAMOND:
return "diamond";
default:
return "ERROR";
}
}
public static Material getMaterial(SwordType type) {
switch (type) {
case WOOD:
return Material.WOOD_SWORD;
case STONE:
return Material.STONE_SWORD;
case IRON:
return Material.IRON_SWORD;
case GOLD:
return Material.GOLD_SWORD;
case DIAMOND:
return Material.DIAMOND_SWORD;
default:
return null;
}
}
public static int getMaxDurability(SwordType type) {
return getMaterial(type).getMaxDurability();
}
public static SwordType getSwordType(Material mat) {
switch (mat) {
case WOOD_SWORD:
return SwordType.WOOD;
case STONE_SWORD:
return SwordType.STONE;
case IRON_SWORD:
return SwordType.IRON;
case GOLD_SWORD:
return SwordType.GOLD;
case DIAMOND_SWORD:
return SwordType.DIAMOND;
default:
return null;
}
}
public static Boolean isSword(Material mat) {
return mat == Material.WOOD_SWORD || mat == Material.STONE_SWORD || mat == Material.IRON_SWORD || mat == Material.GOLD_SWORD || mat == Material.DIAMOND_SWORD;
}
public static SwordType getType(String shortname) {
switch (shortname) {
case "wood":
return SwordType.WOOD;
case "stone":
return SwordType.STONE;
case "iron":
return SwordType.IRON;
case "gold":
return SwordType.GOLD;
case "diamond":
return SwordType.DIAMOND;
default:
return null;
}
}
}

View File

@ -0,0 +1,469 @@
package com.fpghoti.classicswords.item;
import java.lang.reflect.Constructor;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.fpghoti.classicswords.item.CItemType.SwordType;
import com.fpghoti.classicswords.util.Storage;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.NBTTagDouble;
import net.minecraft.server.v1_12_R1.NBTTagInt;
import net.minecraft.server.v1_12_R1.NBTTagList;
import net.minecraft.server.v1_12_R1.NBTTagString;
public class ClassicSword {
public static ItemStack toShield(ItemStack old, SwordType type) {
String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordModel(type));
ItemMeta meta = csword.getItemMeta();
if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) {
name = ometa.getDisplayName();
}else {
name = CItemType.getDefaultName(type);
}
if(ometa.hasLore()) {
meta.setLore(ometa.getLore());
}
}else {
name = CItemType.getDefaultName(type);
}
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName(name);
csword.setItemMeta(meta);
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = CItemType.getSwordType(type);
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"));
NBTTagCompound cstag = new NBTTagCompound();
int dur = old.getType().getMaxDurability() - old.getDurability();
cstag.set("Durability", new NBTTagInt(dur));
cstag.set("Type", new NBTTagString(CItemType.getShortName(type)));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
compound.set("ClassicSwords", cstag);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(old.getEnchantments() != null) {
csword.addUnsafeEnchantments(old.getEnchantments());
}
return csword;
}
public static ItemStack toBlockShield(ItemStack old, SwordType type) {
if(isCShield(old)) {
String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordBlockModel(type));
ItemMeta meta = csword.getItemMeta();
if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) {
name = ometa.getDisplayName();
}else {
name = CItemType.getDefaultName(type);
}
if(ometa.hasLore()) {
meta.setLore(ometa.getLore());
}
}else {
name = CItemType.getDefaultName(type);
}
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName(name);
csword.setItemMeta(meta);
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = CItemType.getSwordType(type);
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"));
NBTTagCompound cstag = new NBTTagCompound();
int dur = getCShieldDurability(old);
cstag.set("Durability", new NBTTagInt(dur));
cstag.set("Type", new NBTTagString(CItemType.getShortName(type)));
NBTTagCompound blocktag = new NBTTagCompound();
blocktag.set("BlockHit", new NBTTagString("BlockHit"));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
compound.set("ClassicSwords", cstag);
compound.set("BlockHit", blocktag);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(old.getEnchantments() != null) {
csword.addUnsafeEnchantments(old.getEnchantments());
}
return csword;
}else {
return null;
}
}
public static ItemStack blockToShield(ItemStack old, SwordType type) {
if(isCBlockShield(old)) {
String name;
ItemStack csword = new ItemStack(Material.SHIELD, 1, CItemType.getSwordModel(type));
ItemMeta meta = csword.getItemMeta();
if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) {
name = ometa.getDisplayName();
}else {
name = CItemType.getDefaultName(type);
}
if(ometa.hasLore()) {
meta.setLore(ometa.getLore());
}
}else {
name = CItemType.getDefaultName(type);
}
meta.setUnbreakable(true);
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
meta.setDisplayName(name);
csword.setItemMeta(meta);
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = CItemType.getSwordType(type);
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"));
NBTTagCompound cstag = new NBTTagCompound();
int dur = getCShieldDurability(old);
cstag.set("Durability", new NBTTagInt(dur));
cstag.set("Type", new NBTTagString(CItemType.getShortName(type)));
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
compound.set("ClassicSwords", cstag);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
if(old.getEnchantments() != null) {
csword.addUnsafeEnchantments(old.getEnchantments());
}
return csword;
}else {
return null;
}
}
public static ItemStack toSword(ItemStack old, SwordType type) {
String name;
ItemStack csword = new ItemStack(CItemType.getMaterial(type), 1);
if(old.getEnchantments() != null) {
csword.addUnsafeEnchantments(old.getEnchantments());
}
ItemMeta meta = csword.getItemMeta();
if(old.hasItemMeta()) {
ItemMeta ometa = old.getItemMeta();
if(ometa.hasDisplayName()) {
name = ometa.getDisplayName();
}else {
name = CItemType.getDefaultName(type);
}
if(ometa.hasLore()) {
meta.setLore(ometa.getLore());
}
}else {
name = CItemType.getDefaultName(type);
}
meta.setUnbreakable(false);
meta.setDisplayName(name);
csword.setItemMeta(meta);
net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(csword);
NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
NBTTagList modifiers = new NBTTagList();
NBTTagCompound damage = CItemType.getSwordType(type);
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"));
NBTTagCompound cstag = new NBTTagCompound();
modifiers.add(damage);
modifiers.add(atspeed);
compound.set("AttributeModifiers", modifiers);
compound.set("ClassicSwords", cstag);
nmsStack.setTag(compound);
csword = CraftItemStack.asBukkitCopy(nmsStack);
csword.setDurability((short)(csword.getType().getMaxDurability() - (short)((int)getCShieldDurability(old))));
return csword;
}
public static Boolean isCShield(ItemStack item) {
if(item == null) {
return false;
}
if(item.getType() != Material.SHIELD) {
return false;
}
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
if(!nms.hasTag() || nms.getTag() == null) {
return false;
}
if(nms.getTag().hasKey("ClassicSwords")) {
return true;
}else {
return false;
}
}
public static Boolean isCBlockShield(ItemStack item) {
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
return nms.getTag() != null && isCShield(item) && nms.getTag().hasKey("ClassicSwords");
}
public static Boolean isBlocking(Player p) {
return Storage.blockers.contains(p);
}
public static Boolean isCSword(ItemStack item) {
if(!(item.getType() == Material.WOOD_SWORD || item.getType() == Material.STONE_SWORD ||item.getType() == Material.IRON_SWORD || item.getType() == Material.GOLD_SWORD || item.getType() == Material.DIAMOND_SWORD)) {
return false;
}
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
if(!nms.hasTag() || nms.getTag() == null) {
return false;
}
if(nms.getTag().hasKey("ClassicSwords")) {
return true;
}else {
return false;
}
}
public static Boolean isCItem(ItemStack item) {
return isCSword(item) || isCShield(item);
}
public static Integer getCShieldDurability(ItemStack item) {
if(!isCItem(item)) {
return null;
}else {
NBTTagCompound cstag = getCSTag(item);
int dur = cstag.getInt("Durability");
return dur;
}
}
public static String getCShieldShortName(ItemStack item) {
if(!isCItem(item)) {
return null;
}else {
NBTTagCompound cstag = getCSTag(item);
String name = cstag.getString("Type");
return name;
}
}
public static void blockToShieldInv(Inventory inv) {
for(int i = 0; i < inv.getSize()-1; i++){
ItemStack item = inv.getItem(i);
if(item != null && isCBlockShield(item)) {
ItemStack newitem = blockToShield(item, CItemType.getType(getCShieldShortName(item)));
inv.setItem(i, newitem);
}
}
}
public static void toShieldInv(Inventory inv) {
for(int i = 0; i < inv.getSize()-1; i++){
ItemStack item = inv.getItem(i);
if(item != null && CItemType.isSword(item.getType())) {
ItemStack newitem = toShield(item, CItemType.getSwordType(item.getType()));
inv.setItem(i, newitem);
}
}
}
public static void toSwordInv(Inventory inv) {
for(int i = 0; i < inv.getSize()-1; i++){
ItemStack item = inv.getItem(i);
if(isCShield(item)) {
ItemStack newitem = toSword(item, CItemType.getType(getCShieldShortName(item)));
inv.setItem(i, newitem);
}
}
}
public static Boolean hasOpenInv(Player p) {
return Storage.inInv.contains(p);
}
public static void setCShieldDurability(Player p, ItemStack item, Integer dur) {
if(isCItem(item)) {
Boolean skip = false;
if(item.containsEnchantment(Enchantment.DURABILITY)) {
int level = item.getEnchantmentLevel(Enchantment.DURABILITY);
int chance = (100/(level+1));
int result = Storage.random.nextInt(101);
skip = result > chance;
}
if(!skip) {
NBTTagCompound cstag = getCSTag(item);
cstag.set("Durability", new NBTTagInt(dur));
p.getInventory().setItemInMainHand(updateCSTag(item, cstag));
}
}
}
public static NBTTagCompound getCSTag(ItemStack item) {
if(!isCItem(item)) {
return null;
}else {
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
NBTTagCompound cstag = (NBTTagCompound) nms.getTag().get("ClassicSwords");
return cstag;
}
}
public static ItemStack updateCSTag(ItemStack item, NBTTagCompound tag) {
if(isCItem(item)) {
net.minecraft.server.v1_12_R1.ItemStack nms = CraftItemStack.asNMSCopy(item);
nms.getTag().set("ClassicSwords", tag);
return CraftItemStack.asBukkitCopy(nms);
}else {
return null;
}
}
public static void breakHeldItem(Player p) {
p.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_BREAK, 10.0F, 1.0F);
}
public static void damageCItem(Player p, ItemStack item, int amount) {
int dur = ClassicSword.getCShieldDurability(item);
dur = dur - amount;
if(dur <= 0) {
sendActionbar(p, "§eDurability: 0");
breakHeldItem(p);
}else {
if(isCItem(item)) {
sendActionbar(p, "§eDurability: " + dur);
setCShieldDurability(p, item, dur);
}
}
}
//BY KNOAPP ON SPIGOT
public static void sendActionbar(Player player, String msg) {
try {
Constructor<?> constructor = getNMSClass("PacketPlayOutChat").getConstructor(getNMSClass("IChatBaseComponent"), getNMSClass("ChatMessageType"));
Object icbc = getNMSClass("IChatBaseComponent").getDeclaredClasses()[0].getMethod("a", String.class).invoke(null, "{\"text\":\"" + msg + "\"}");
Object packet = constructor.newInstance(icbc, getNMSClass("ChatMessageType").getEnumConstants()[2]);
Object entityPlayer= player.getClass().getMethod("getHandle").invoke(player);
Object playerConnection = entityPlayer.getClass().getField("playerConnection").get(entityPlayer);
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Class<?> getNMSClass(String name) {
try {
return Class.forName("net.minecraft.server." + getVersion() + "." + name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
public static String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
}
//////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,74 @@
package com.fpghoti.classicswords.item;
import com.fpghoti.classicswords.util.Storage;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
import net.minecraft.server.v1_12_R1.NBTTagInt;
import net.minecraft.server.v1_12_R1.NBTTagString;
public class SetAttributes {
public static void defineSwords() {
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"));
Storage.damagetag.put("diamond", damage);
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"));
Storage.damagetag.put("wood", damage);
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"));
Storage.damagetag.put("stone", damage);
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"));
Storage.damagetag.put("iron", damage);
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"));
Storage.damagetag.put("gold", damage);
}
}

View File

@ -0,0 +1,47 @@
package com.fpghoti.classicswords.util;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class Functions {
public Player playerGet(String uuid){
UUID id = UUID.fromString(uuid);
Player p = Bukkit.getPlayer(id);
return p;
}
public static Player getEP(String playername){
Player p = null;
for(Player item : Bukkit.getOnlinePlayers()){
if(playername.equalsIgnoreCase(item.getName())){
p = item;
}
}
return p;
}
public static boolean isDigit(String s){
return s.matches("[0-9]+");
}
public static boolean isInteger(String str, int r){
if(str.isEmpty()){
return false;
}
for(int i = 0; i < str.length(); i++){
if((i == 0) && (str.charAt(i) == '-')){
if(str.length() == 1) {
return false;
}
}else if(Character.digit(str.charAt(i), r) < 0) {
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,33 @@
package com.fpghoti.classicswords.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import io.netty.util.internal.ConcurrentSet;
import net.minecraft.server.v1_12_R1.NBTTagCompound;
public class Storage {
public static ConcurrentHashMap<String, Boolean> bools = new ConcurrentHashMap<>();
public static HashMap<String, NBTTagCompound> damagetag = new HashMap<>();
public static Set<Material> instabreaks = new HashSet<>();
public static Set<Player> inInv = new HashSet<>();
public static ConcurrentSet<Player> blockers = new ConcurrentSet<>();
public static ConcurrentSet<Player> swingers = new ConcurrentSet<>();
public static ConcurrentSet<Player> bswingers = new ConcurrentSet<>();
public static Random random = new Random();
public static Map<UUID, Long> regens = new HashMap<>();
public static ConcurrentHashMap<Player, Player> recent = new ConcurrentHashMap<>();
public static ConcurrentHashMap<Player, Double> recenthealth = new ConcurrentHashMap<>();
public static ConcurrentSet<Player> kb = new ConcurrentSet<>();
public static ConcurrentSet<Player> great = new ConcurrentSet<>();
public static ConcurrentSet<Player> perfect = new ConcurrentSet<>();
}

7
src/plugin.yml Normal file
View File

@ -0,0 +1,7 @@
main: com.fpghoti.classicswords.ClassicSwordsMain
version: BETA-0.1
name: ClassicSwords
descripion: Bring back the old combat!
commands:
CSword:
description: Spawns a CSword