generated from devcordde/PluginJamGradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8289bff
commit 0ee059b
Showing
3 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package club.devcord.gamejam; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.player.PlayerTeleportEvent; | ||
import org.bukkit.scheduler.BukkitTask; | ||
|
||
import java.util.*; | ||
|
||
public class Lagger { | ||
private final Nigulpyggub plugin; | ||
private final Map<Player, List<Location>> playerLocations = new HashMap<>(); | ||
private final Random random = new Random(); | ||
private final List<BukkitTask> tasks = new ArrayList<>(); | ||
|
||
public Lagger(Nigulpyggub plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void start() { | ||
stop(); | ||
tasks.add(plugin.getServer().getScheduler().runTaskTimer(plugin, this::saveLocations, 10, 10)); | ||
tasks.add(plugin.getServer().getScheduler().runTaskTimer(plugin, this::lagPlayers, 10, 60)); | ||
} | ||
|
||
public void stop() { | ||
tasks.forEach(BukkitTask::cancel); | ||
} | ||
|
||
private void saveLocations() { | ||
plugin.getServer().getOnlinePlayers().forEach(player -> { | ||
var locations = playerLocations.getOrDefault(player, new ArrayList<>()); | ||
if(locations.size() > 3) { | ||
locations.removeFirst(); | ||
} | ||
locations.add(player.getLocation()); | ||
playerLocations.put(player, locations); | ||
}); | ||
} | ||
|
||
private void lagPlayers() { | ||
plugin.getServer().getOnlinePlayers().forEach(player -> { | ||
var locations = playerLocations.getOrDefault(player, new ArrayList<>()); | ||
if(random.nextInt(0, 100) < 5 && !locations.isEmpty()) { | ||
var location = locations.get(random.nextInt(locations.size())); | ||
player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
package club.devcord.gamejam; | ||
|
||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import org.bukkit.GameMode; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
public class PlayerJoinListener implements Listener { | ||
|
||
@EventHandler | ||
public void activatePlayerResourcePack(PlayerJoinEvent event) { | ||
public void onPlayerJoin(PlayerJoinEvent event) { | ||
event.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize("<rainbow><bold>Welcome to our test server, have fun and enjoy our little theme park!")); | ||
|
||
if(!event.getPlayer().isOp()) { | ||
event.getPlayer().setGameMode(GameMode.ADVENTURE); | ||
} | ||
|
||
event.getPlayer().setResourcePack("https://panel.traidio.net/resourcepack.zip"); | ||
} | ||
} |