Browse Source

Added full 1.8-1.14 support. 1.14 still buggy, but works

master
pintux98 5 years ago
parent
commit
2a01752aec
  1. 1
      MultiArena-TheBridge/.classpath
  2. 5
      MultiArena-TheBridge/src/cx/sfy/TheBridge/hologram/TruenoHologramAPI.java
  3. 280
      MultiArena-TheBridge/src/cx/sfy/TheBridge/hologram/TruenoHologram_v1_14_R1.java
  4. 29
      MultiArena-TheBridge/src/cx/sfy/TheBridge/listeners/PlayerListener.java

1
MultiArena-TheBridge/.classpath

@ -12,5 +12,6 @@
<classpathentry kind="lib" path="C:/Users/pintu/Desktop/pindev/spigot-related/spigot-1.12.2.jar"/>
<classpathentry kind="lib" path="C:/Users/pintu/Desktop/pindev/spigot-related/spigot-1.13.2.jar"/>
<classpathentry kind="lib" path="C:/Users/pintu/Desktop/pindev/spigot-related/worldedit-bukkit-6.1.9.jar"/>
<classpathentry kind="lib" path="C:/Users/pintu/Desktop/pindev/spigot-related/spigot-1.14.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

5
MultiArena-TheBridge/src/cx/sfy/TheBridge/hologram/TruenoHologramAPI.java

@ -38,7 +38,10 @@ public class TruenoHologramAPI {
return new TruenoHologram_v1_12_R1();
} else if (version.equals("v1_13_R2")) {
return new TruenoHologram_v1_13_R2();
} else {
}else if (version.equals("v1_14_R1")) {
return new TruenoHologram_v1_14_R1();
}
else {
Bukkit.getLogger().log(Level.SEVERE, ChatColor.RED + "Unsopported server version.");
return null;
}

280
MultiArena-TheBridge/src/cx/sfy/TheBridge/hologram/TruenoHologram_v1_14_R1.java

@ -0,0 +1,280 @@
package cx.sfy.TheBridge.hologram;
import java.util.ArrayList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import net.minecraft.server.v1_14_R1.EntityArmorStand;
import net.minecraft.server.v1_14_R1.EntityTypes;
import net.minecraft.server.v1_14_R1.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_14_R1.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_14_R1.WorldServer;
public class TruenoHologram_v1_14_R1 implements TruenoHologram{
private Location location;
private ArrayList<String> lines;
private double linesdistance = 0.30;
private ArrayList<ArmorStand> armor_lines = new ArrayList<>();
private ArrayList<EntityArmorStand> NmsArmorLines = new ArrayList<>();
private Player player = null;
@Override
public void setupWorldHologram(Location loc, ArrayList<String> lines) {
this.location = loc.clone();
this.lines = lines;
}
@Override
public void setupPlayerHologram(Player player, Location loc, ArrayList<String> lines) {
this.player = player;
this.location = loc.clone();
this.lines = lines;
}
@Override
public Location getLocation(){
return this.location;
}
@Override
public Player getPlayer(){
return player;
}
private void NmsDestroy(EntityArmorStand hololine){
final PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(hololine.getId());
((CraftPlayer) this.player).getHandle().playerConnection.sendPacket(packet);
}
private Location getNmsLocation(EntityArmorStand hololine){
return new Location(hololine.getWorld().getWorld(), hololine.locX, hololine.locY, hololine.locZ);
}
private void NmsSpawn(EntityArmorStand stand, String line, Location loc){
stand.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0, 0);
stand.setCustomName(CraftChatMessage.fromStringOrNull(line));
stand.setCustomNameVisible(true);
stand.setNoGravity(true);
stand.setSmall(true);
stand.setInvisible(true);
stand.setBasePlate(false);
stand.setArms(false);
if(!line.equals("")){
final PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(stand);
((CraftPlayer) this.player).getHandle().playerConnection.sendPacket(packet);
}
}
private void spawn(){
int ind = 0;
for(final String line : lines){
Location finalLoc = location.clone();
finalLoc.setY(location.getY()+(linesdistance*lines.size()));
if(this.player!=null){
if(ind>0) finalLoc = getNmsLocation(NmsArmorLines.get(ind-1)); finalLoc.setY(finalLoc.getY()-linesdistance);
final WorldServer s = ((CraftWorld)this.location.getWorld()).getHandle();
final EntityArmorStand stand = new EntityArmorStand(EntityTypes.ARMOR_STAND, s);
NmsSpawn(stand, line, finalLoc);
NmsArmorLines.add(stand);
}
else{
if(ind>0) finalLoc = armor_lines.get(ind-1).getLocation(); finalLoc.setY(finalLoc.getY()-linesdistance);
final ArmorStand Armorline = (ArmorStand) location.getWorld().spawnEntity(finalLoc, EntityType.ARMOR_STAND);
Armorline.setBasePlate(false);
Armorline.setCustomNameVisible(true);
Armorline.setGravity(false);
Armorline.setCanPickupItems(false);
Armorline.setCustomName(line);
Armorline.setSmall(true);
Armorline.setVisible(false);
armor_lines.add(Armorline);
if(line.equals("")) Armorline.remove();
}
ind++;
}
}
private void despawn(){
if(this.player!=null){
for(final EntityArmorStand nmsStand : NmsArmorLines)
NmsDestroy(nmsStand);
NmsArmorLines.clear();
}
else{
for(final ArmorStand line : armor_lines)
line.remove();
armor_lines.clear();
}
}
@Override
public void setDistanceBetweenLines(Double distance){
this.linesdistance = distance;
}
@Override
public void display(){
spawn();
}
@Override
public void update(ArrayList<String> lines){
if(this.player != null){
int ind = 0;
for(final String newline : lines)
if(this.lines.size()>= ind){
final String oldline = this.lines.get(ind);
if(!newline.equals(oldline))
if(!newline.equals("")){
final EntityArmorStand oldstand = NmsArmorLines.get(ind);
Location finalLoc = location.clone();
finalLoc.setY(location.getY()+(linesdistance*lines.size()));
if(ind>0) finalLoc = getNmsLocation(NmsArmorLines.get(ind-1)); finalLoc.setY(finalLoc.getY()-linesdistance);
final WorldServer s = ((CraftWorld)this.location.getWorld()).getHandle();
final EntityArmorStand stand = new EntityArmorStand(EntityTypes.ARMOR_STAND, s);
NmsSpawn(stand, newline, finalLoc);
this.NmsArmorLines.set(ind, stand);
this.lines.set(ind, newline);
NmsDestroy(oldstand);
}
else{
this.lines.set(ind, newline);
final EntityArmorStand oldstand = NmsArmorLines.get(ind);
NmsDestroy(oldstand);
}
ind++;
}
else{
Location finalLoc = location.clone();
finalLoc.setY(location.getY()+(linesdistance*lines.size()));
if(ind>0) finalLoc = getNmsLocation(NmsArmorLines.get(ind-1)); finalLoc.setY(finalLoc.getY()-linesdistance);
final WorldServer s = ((CraftWorld)this.location.getWorld()).getHandle();
final EntityArmorStand stand = new EntityArmorStand(EntityTypes.ARMOR_STAND, s);
NmsSpawn(stand, newline, finalLoc);
this.NmsArmorLines.add(stand);
this.lines.add(newline);
}
if(lines.size() > this.lines.size()){
final int dif = lines.size() - this.lines.size();
for(int in = 0; in <=dif; in++){
final int arrayind = (this.lines.size()-1)-in;
this.lines.remove(arrayind);
NmsDestroy(this.NmsArmorLines.get(arrayind));
this.NmsArmorLines.remove(arrayind);
}
}
}
else{
int ind = 0;
for(final String newline : lines)
if(this.lines.size()>= ind){
final String oldline = this.lines.get(ind);
if(!newline.equals(oldline))
if(newline != "")
this.armor_lines.get(ind).setCustomName(newline);
else{
this.lines.set(ind, newline);
final ArmorStand oldstand = armor_lines.get(ind);
oldstand.remove();
}
ind++;
}
else{
Location finalLoc = location.clone();
finalLoc.setY(location.getY()+(linesdistance*lines.size()));
if(ind>0) finalLoc = armor_lines.get(ind-1).getLocation(); finalLoc.setY(finalLoc.getY()-linesdistance);
final ArmorStand Armorline = (ArmorStand) location.getWorld().spawnEntity(finalLoc, EntityType.ARMOR_STAND);
Armorline.setBasePlate(false);
Armorline.setCustomNameVisible(true);
Armorline.setGravity(false);
Armorline.setCanPickupItems(false);
Armorline.setCustomName(newline);
Armorline.setSmall(true);
Armorline.setVisible(false);
armor_lines.add(Armorline);
this.lines.add(newline);
}
if(lines.size() > this.lines.size()){
final int dif = lines.size() - this.lines.size();
for(int in = 0; in <=dif; in++){
final int arrayind = (this.lines.size()-1)-in;
this.lines.remove(arrayind);
this.armor_lines.get(arrayind).remove();
this.armor_lines.remove(arrayind);
}
}
}
}
@Override
public void updateLine(int index, String text){
if(this.lines.size() >= index){
final int realindex = (this.lines.size()-1)-index;
final String oldtext = this.lines.get(realindex);
if(!text.equals(oldtext)){
if(this.player != null){
if(text != ""){
final EntityArmorStand oldstand = NmsArmorLines.get(realindex);
Location finalLoc = location.clone();
finalLoc.setY(location.getY()+(linesdistance*lines.size()));
if(realindex>0) finalLoc = getNmsLocation(NmsArmorLines.get(realindex-1)); finalLoc.setY(finalLoc.getY()-linesdistance);
final WorldServer s = ((CraftWorld)this.location.getWorld()).getHandle();
final EntityArmorStand stand = new EntityArmorStand(EntityTypes.ARMOR_STAND, s);
NmsSpawn(stand, text, finalLoc);
this.NmsArmorLines.set(realindex, stand);
NmsDestroy(oldstand);
}
else{
this.lines.set(realindex, text);
final EntityArmorStand oldstand = NmsArmorLines.get(realindex);
NmsDestroy(oldstand);
}
} else if(text != "")
this.armor_lines.get(realindex).setCustomName(text);
else{
final ArmorStand oldstand = armor_lines.get(realindex);
oldstand.remove();
}
this.lines.set(realindex, text);
}
}
}
@Override
public void removeLine(int index){
if(this.lines.size() >= index){
final int realindex = (this.lines.size()-1)-index;
if(this.player != null){
final EntityArmorStand stand = NmsArmorLines.get(realindex);
this.NmsArmorLines.remove(stand);
NmsDestroy(stand);
} else
this.armor_lines.get(realindex).remove();
this.lines.remove(realindex);
}
}
@Override
public void delete(){
despawn();
this.player = null;
this.NmsArmorLines = new ArrayList<>();
this.armor_lines = new ArrayList<>();
this.lines = new ArrayList<>();
this.location = null;
}
}

29
MultiArena-TheBridge/src/cx/sfy/TheBridge/listeners/PlayerListener.java

@ -35,7 +35,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -549,9 +549,10 @@ public class PlayerListener implements Listener {
@EventHandler
public void onClose(InventoryCloseEvent e) {
final Player p = (Player) e.getPlayer();
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.type.title")))
InventoryView inv = e.getView();
if (inv.getTitle().equals(plugin.getLang().get("menus.type.title")))
page.remove(p);
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.hotbar.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.hotbar.title"))) {
InventoryData.getInventoryData(p).restore();
InventoryData.remove(p);
}
@ -560,7 +561,7 @@ public class PlayerListener implements Listener {
@EventHandler
public void onMenu(InventoryClickEvent e) {
final Player p = (Player) e.getWhoClicked();
final Inventory inv = e.getInventory();
final InventoryView inv = e.getView();
if (inv.getTitle() == null)
return;
@ -640,7 +641,7 @@ public class PlayerListener implements Listener {
}
}
}
if (e.getInventory().getTitle()
if (inv.getTitle()
.equals(plugin.getAchievement().get("title").replaceAll("<player>", p.getName()))) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)
@ -665,7 +666,7 @@ public class PlayerListener implements Listener {
e.setCancelled(true);
}
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("shop.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("shop.title"))) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)
return;
@ -674,7 +675,7 @@ public class PlayerListener implements Listener {
if (e.getCurrentItem().getItemMeta().getDisplayName().equals(plugin.getLang().get("shop.close.nameItem")))
p.getOpenInventory().close();
}
if (e.getInventory().getTitle().equals(plugin.getCages().get("title"))) {
if (inv.getTitle().equals(plugin.getCages().get("title"))) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)
return;
@ -708,7 +709,7 @@ public class PlayerListener implements Listener {
PlayerStat.getPlayerStat(p).setCage(cage.getId());
}
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.type.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.type.title"))) {
e.setCancelled(true);
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR)
return;
@ -719,7 +720,7 @@ public class PlayerListener implements Listener {
.equals(plugin.getLang().get("menus.type.four.nameItem")))
plugin.getGMU().openGameFourMenu(p);
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.hotbar.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.hotbar.title"))) {
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) {
e.setCancelled(true);
return;
@ -740,7 +741,7 @@ public class PlayerListener implements Listener {
e.setCancelled(true);
}
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.game.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.game.title"))) {
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR
|| e.getSlotType().equals(SlotType.OUTSIDE))
return;
@ -759,7 +760,7 @@ public class PlayerListener implements Listener {
p.sendMessage(plugin.getLang().get("messages.gameAlreadyStart"));
}
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.gameFour.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.gameFour.title"))) {
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR
|| e.getSlotType().equals(SlotType.OUTSIDE))
return;
@ -781,7 +782,7 @@ public class PlayerListener implements Listener {
}
}
if (plugin.getGM().getGameByPlayer(p) != null)
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.team.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.team.title"))) {
e.setCancelled(true);
final Game game = plugin.getGM().getGameByPlayer(p);
if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§9")) {
@ -828,7 +829,7 @@ public class PlayerListener implements Listener {
}
}
if (plugin.getGM().getGameFourByPlayer(p) != null) {
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.options.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.options.title"))) {
e.setCancelled(true);
if (Bukkit.getPlayer(e.getCurrentItem().getItemMeta().getDisplayName().replaceAll("§7", "")) == null)
return;
@ -866,7 +867,7 @@ public class PlayerListener implements Listener {
plugin.getSOM().openOptionsMenu(p);
}
}
if (e.getInventory().getTitle().equals(plugin.getLang().get("menus.teamFour.title"))) {
if (inv.getTitle().equals(plugin.getLang().get("menus.teamFour.title"))) {
e.setCancelled(true);
final GameFour game = plugin.getGM().getGameFourByPlayer(p);
if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§9")) {

Loading…
Cancel
Save