icontrolu/src/main/java/pw/kaboom/icontrolu/Main.java

53 lines
1.5 KiB
Java
Raw Normal View History

2018-08-06 00:36:30 +00:00
package pw.kaboom.icontrolu;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
2019-12-17 16:59:28 +00:00
import org.bukkit.potion.PotionEffectType;
2018-08-06 00:36:30 +00:00
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
2019-12-17 16:59:28 +00:00
import pw.kaboom.icontrolu.commands.CommandIcu;
import pw.kaboom.icontrolu.utilities.PlayerList;
2018-08-06 00:36:30 +00:00
2019-12-17 16:59:28 +00:00
public final class Main extends JavaPlugin {
@Override
2018-08-06 00:36:30 +00:00
public void onEnable() {
2019-12-15 05:32:41 +00:00
/* Setup scoreboard team to prevent player collisions */
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
2019-12-20 21:37:38 +00:00
final Team team = scoreboard.getTeam("icuCollision");
2018-08-06 00:36:30 +00:00
if (team != null) {
team.unregister();
}
2019-12-15 05:32:41 +00:00
/* Commands */
this.getCommand("icu").setExecutor(new CommandIcu());
2018-08-06 00:36:30 +00:00
2019-12-15 05:32:41 +00:00
new Tick().runTaskTimer(this, 0, 1);
2019-12-17 16:59:28 +00:00
this.getServer().getPluginManager().registerEvents(new ControlPlayer(), this);
2018-08-06 00:36:30 +00:00
}
2019-12-17 16:59:28 +00:00
@Override
2018-08-06 00:36:30 +00:00
public void onDisable() {
for (Player controller: Bukkit.getOnlinePlayers()) {
2019-12-17 16:59:28 +00:00
final Player target = PlayerList.getTarget(controller.getUniqueId());
2019-12-15 05:32:41 +00:00
2018-08-06 00:36:30 +00:00
if (target != null) {
for (Player player: Bukkit.getOnlinePlayers()) {
player.showPlayer(this, controller);
2018-08-06 00:36:30 +00:00
}
2019-12-15 05:32:41 +00:00
final Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
2019-12-20 21:37:38 +00:00
final Team team = scoreboard.getTeam("icuCollision");
2019-12-15 05:32:41 +00:00
2018-08-06 00:36:30 +00:00
if (team != null) {
team.unregister();
}
controller.removePotionEffect(PotionEffectType.INVISIBILITY);
controller.sendMessage("You are no longer controlling \"" + target.getName() + "\" due to server reload");
}
}
}
}