pintux98
6 years ago
8 changed files with 326 additions and 34 deletions
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>thebridge</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
</natures> |
||||
|
</projectDescription> |
@ -0,0 +1,278 @@ |
|||||
|
package cx.sfy.TheBridge.hologram; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
|
||||
|
import org.bukkit.Location; |
||||
|
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld; |
||||
|
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer; |
||||
|
import org.bukkit.entity.ArmorStand; |
||||
|
import org.bukkit.entity.EntityType; |
||||
|
import org.bukkit.entity.Player; |
||||
|
|
||||
|
import net.minecraft.server.v1_13_R2.EntityArmorStand; |
||||
|
import net.minecraft.server.v1_13_R2.IChatBaseComponent.ChatSerializer; |
||||
|
import net.minecraft.server.v1_13_R2.PacketPlayOutEntityDestroy; |
||||
|
import net.minecraft.server.v1_13_R2.PacketPlayOutSpawnEntityLiving; |
||||
|
import net.minecraft.server.v1_13_R2.WorldServer; |
||||
|
|
||||
|
public class TruenoHologram_v1_13_R2 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(ChatSerializer.a(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(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(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(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(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; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue