Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.kihei.firstplugin;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerMoveEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.util.ArrayList;
- import java.util.HashMap;
- public final class FirstPlugin extends JavaPlugin {
- static ArrayList<Player> frozenList = new ArrayList<>();
- @Override
- public void onEnable() {
- //Creating the Movement Listener class
- MovementListener moveListener = new MovementListener(this); // Giving "this" as the parameter for the constructor
- // \/ The listener
- getServer().getPluginManager().registerEvents(moveListener, this);
- // /\ The plugin who is responsible for the listener
- // HOMEWORK:
- //frozenList.add(Player Object)
- //frozenList.remove(Player Object)
- }
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
- //Can't actually be called under normal circumstances
- if (!command.getName().equals("freeze")) {
- sender.sendMessage("This command was not found!");
- return true; //Return true -> the plugin command was successfully terminated
- }
- //It can also be the console or a command block. Making sure that the sender is indeed a player
- if (!(sender instanceof Player)) {
- sender.sendMessage("Only players can send this command.");
- return true;
- }
- //Java still doesn't know for sure that sender is a player. So we enforce it. (CASTING)
- Player p = (Player) sender;
- //Checking if the player is currently inside the hashmap. If they aren't we know for sure they aren't frozen.
- if (!frozenList.contains(p)) {
- //Called if the player is not inside the frozen hashmap.
- frozenList.add(p);
- } else {
- //We check whether the player is frozen or not
- frozenList.remove(p);
- }
- return true;
- //Lets minecraft know that the code successfully terminated
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement