Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZombieStriker authored Mar 10, 2018
1 parent 7c9a219 commit f9b712d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 31 deletions.
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
1.0.2
//Bukkits multi-world system is extremely hacky
Fixed problem with Nether
Removeddebug messages

1.0.1
Fixed issue with nether/end

1.0.0
init post
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main: me.zombie_striker.wcsr.Main
version: 1.0.0
version: 1.0.2
name: WorldChangeScreenRemover
softdepend: [ProtocolLib]
author:
Expand Down
104 changes: 76 additions & 28 deletions src/me/zombie_striker/wcsr/MagicPacketHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,34 @@
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World.Environment;
import org.bukkit.event.*;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import com.comphenix.protocol.*;
import com.comphenix.protocol.events.*;
import com.comphenix.protocol.wrappers.BlockPosition;

public class MagicPacketHolder implements Listener {

private List<UUID> respawnredPlayers = new ArrayList<>();
private List<UUID> playersGoingToSametype = new ArrayList<>();

private HashMap<UUID, Long> lasttele = new HashMap<>();
private List<UUID> barredPlayers = new ArrayList<>();

public final JavaPlugin thi;

public PacketContainer tempp = null;

boolean forceNether = false;

public final void setHolder(PacketContainer p) {
tempp = p;
}
Expand All @@ -32,11 +42,34 @@ public final PacketContainer getHolder() {
return tempp;
}

long tickCounter = 0;

public MagicPacketHolder(JavaPlugin p) {
thi = p;

final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

new BukkitRunnable() {

@Override
public void run() {
tickCounter++;
tickCounter %= 100000;

}
}.runTaskLater(thi, 1);
/*
* for (final PacketType p2 : PacketType.values()) if (p2.isServer() &&
* !p2.name().toLowerCase().contains("entity") &&
* !p2.name().toLowerCase().contains("custom") &&
* !p2.name().toLowerCase().contains("chunk") &&
* !p2.name().toLowerCase().contains("slot"))
*
* protocolManager.addPacketListener(new PacketAdapter(thi,
* ListenerPriority.NORMAL, p2) {
*
* @Override public void onPacketSending(final PacketEvent event) {
* System.out.print(p2.name()); } });
*/
protocolManager
.addPacketListener(new PacketAdapter(thi, ListenerPriority.NORMAL, PacketType.Play.Server.RESPAWN) {
@Override
Expand All @@ -50,16 +83,18 @@ public void run() {
}.runTaskLater(thi, 2);
} else {
if (playersGoingToSametype.contains(event.getPlayer().getUniqueId())) {
new BukkitRunnable() {
public void run() {
playersGoingToSametype.remove(event.getPlayer().getUniqueId());
}
}.runTaskLater(thi, 2);

playersGoingToSametype.remove(event.getPlayer().getUniqueId());
event.setCancelled(true);
PacketContainer pc2 = protocolManager.createPacket(PacketType.Play.Server.UNLOAD_CHUNK);
pc2.getIntegers().write(0, event.getPlayer().getLocation().getChunk().getX()).write(1,
event.getPlayer().getLocation().getChunk().getZ());

try {
protocolManager.sendServerPacket(event.getPlayer(), pc2);
} catch (InvocationTargetException e) {
e.printStackTrace();
}

for (int x = event.getPlayer().getLocation().getChunk().getX() - 8; x < event
.getPlayer().getLocation().getChunk().getX() + 8; x++) {
for (int z = event.getPlayer().getLocation().getChunk().getZ() - 8; z < event
Expand All @@ -78,23 +113,38 @@ public void run() {
}
}
} else {
// The hack level is over 9000!
if (lasttele.containsKey(event.getPlayer().getUniqueId())) {
long tick = lasttele.get(event.getPlayer().getUniqueId());
if (tick == tickCounter)
barredPlayers.add(event.getPlayer().getUniqueId());
}
lasttele.put(event.getPlayer().getUniqueId(), tickCounter);

if (getHolder() == null) {
if (event.getPacket().getIntegers().read(0) == -1) {
setHolder(event.getPacket());
event.setCancelled(true);
// Don't fault me
// If in one tick the packet is still there, this was really meant to go to the
if (forceNether == false) {
event.setCancelled(true);
setHolder(event.getPacket());
}

// nether
new BukkitRunnable() {

@Override
public void run() {
if (getHolder() != null) {
try {
protocolManager.sendServerPacket(event.getPlayer(),
getHolder());
} catch (InvocationTargetException e) {
e.printStackTrace();
final Location temp = event.getPlayer().getLocation();
if (temp.getWorld().getEnvironment() == Environment.NETHER) {
event.getPlayer()
.teleport(Bukkit.getWorlds().get(0).getSpawnLocation());
new BukkitRunnable() {
@Override
public void run() {
forceNether = true;
event.getPlayer().teleport(temp);
forceNether = false;
}
}.runTaskLater(thi, 0);
}
setHolder(null);
}
Expand All @@ -107,25 +157,23 @@ public void run() {
}
}
}

for (int i = 0; i < 25; i++) {
new BukkitRunnable() {
public void run() {
event.getPlayer().teleport(event.getPlayer().getLocation());
}
}.runTaskLater(thi, i);
}
}
});
}

@EventHandler(priority = EventPriority.HIGHEST)
public void onWorldChange(PlayerChangedWorldEvent e) {
if (e.getPlayer().getWorld().getEnvironment() == e.getFrom().getEnvironment()
|| (!e.getFrom().getName().toLowerCase().contains("nether")
|| !e.getFrom().getName().toLowerCase().contains("the_end")))
&& (!e.getFrom().getName().toLowerCase().contains("nether")
&& !e.getFrom().getName().toLowerCase().contains("the_end")
&& (!e.getPlayer().getWorld().getName().toLowerCase().contains("nether")
&& !e.getPlayer().getWorld().getName().toLowerCase().contains("the_end"))))
if (e.getPlayer().getWorld() != e.getFrom())
playersGoingToSametype.add(e.getPlayer().getUniqueId());
if (barredPlayers.contains(e.getPlayer().getUniqueId()))
barredPlayers.remove(e.getPlayer().getUniqueId());
else
playersGoingToSametype.add(e.getPlayer().getUniqueId());

}

@EventHandler
Expand Down
4 changes: 2 additions & 2 deletions src/me/zombie_striker/wcsr/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Main extends JavaPlugin {
@Override
public void onEnable() {
try {
// if (Bukkit.getPluginManager().getPlugin("PluginConstructorAPI") == null)
//if (Bukkit.getPluginManager().getPlugin("PluginConstructorAPI") == null)
//GithubDependDownloader.autoUpdate(this, new File(getDataFolder().getParentFile(),"PluginConstructorAPI.jar"), "ZombieStriker", "PluginConstructorAPI", "PluginConstructorAPI.jar");
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -26,7 +26,7 @@ public void onEnable() {
}catch(Error|Exception e){

}
if(getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
if(!getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
Bukkit.broadcastMessage("[WorldChangeScreenRemover] ProtocolLib has not been installed. Installing now");
new DependencyDownloader(this, ProjectID.PROTOCOLLIB);
}
Expand Down

0 comments on commit f9b712d

Please sign in to comment.