mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-17 21:06:11 +00:00
Merge pull request #280 from CoolJWB/development
Potion command fix & performance
This commit is contained in:
commit
451ef8f009
@ -12,11 +12,14 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import me.totalfreedom.totalfreedommod.FreedomService;
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
||||||
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.CoreProtectAPI;
|
import net.coreprotect.CoreProtectAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.data.BlockData;
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
public class FAWEBridge extends FreedomService
|
public class FAWEBridge extends FreedomService
|
||||||
@ -29,7 +32,7 @@ public class FAWEBridge extends FreedomService
|
|||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
{
|
{
|
||||||
api = plugin.cpb.getCoreProtectAPI();
|
api = ((CoreProtect)Bukkit.getPluginManager().getPlugin("CoreProtect")).getAPI();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs.
|
* Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs.
|
||||||
@ -127,7 +130,12 @@ public class FAWEBridge extends FreedomService
|
|||||||
if (!pattern.apply(blockVector3).getBlockType().getMaterial().isAir())
|
if (!pattern.apply(blockVector3).getBlockType().getMaterial().isAir())
|
||||||
{
|
{
|
||||||
blocksPlaced.putIfAbsent(playerAndSessionEntry, new AbstractMap.SimpleEntry<>(pattern, new ArrayList<>()));
|
blocksPlaced.putIfAbsent(playerAndSessionEntry, new AbstractMap.SimpleEntry<>(pattern, new ArrayList<>()));
|
||||||
blocksPlaced.get(playerAndSessionEntry).getValue().add(new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass()));
|
BlockVector3 vectorClone = new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass());
|
||||||
|
|
||||||
|
if (!blocksPlaced.get(playerAndSessionEntry).getValue().contains(vectorClone))
|
||||||
|
{
|
||||||
|
blocksPlaced.get(playerAndSessionEntry).getValue().add(vectorClone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,23 +146,23 @@ public class FAWEBridge extends FreedomService
|
|||||||
{
|
{
|
||||||
world = server.getWorld(editSession.getWorld().getName());
|
world = server.getWorld(editSession.getWorld().getName());
|
||||||
}
|
}
|
||||||
List<Block> blocks = new ArrayList<>();
|
List<BlockState> blocks = new ArrayList<>();
|
||||||
|
|
||||||
for (BlockVector3 blockVector3 : region)
|
for (BlockVector3 blockVector3 : region)
|
||||||
{
|
{
|
||||||
blocks.add(world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()));
|
blocks.add(world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()).getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
logBlockEdit(playerName, editSession, pattern, blocks);
|
logBlockEdit(playerName, editSession, pattern, blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, List<Block> blocks)
|
public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, List<BlockState> blocks)
|
||||||
{
|
{
|
||||||
Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession);
|
Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession);
|
||||||
|
|
||||||
server.getScheduler().scheduleSyncDelayedTask(plugin, () ->
|
server.getScheduler().scheduleAsyncDelayedTask(plugin, () ->
|
||||||
{
|
{
|
||||||
for (Block block : blocks)
|
for (BlockState block : blocks)
|
||||||
{
|
{
|
||||||
BlockVector3 blockVector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
BlockVector3 blockVector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ());
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||||||
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
||||||
@CommandParameters(
|
@CommandParameters(
|
||||||
description = "Manipulate your potion effects. Duration is measured in server ticks (~20 ticks per second).",
|
description = "Manipulate your potion effects. Duration is measured in server ticks (~20 ticks per second).",
|
||||||
usage = "/<command> <list | clear [target name] | add <type> <duration> <amplifier> [target name]>",
|
usage = "/<command> <list | clearall | clear [target name] | add <type> <duration> <amplifier> [target name]>",
|
||||||
aliases="effect")
|
aliases="effect")
|
||||||
public class Command_potion extends FreedomCommand
|
public class Command_potion extends FreedomCommand
|
||||||
{
|
{
|
||||||
@ -25,153 +25,149 @@ public class Command_potion extends FreedomCommand
|
|||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||||
{
|
{
|
||||||
if (args.length == 1 || args.length == 2)
|
switch (args.length)
|
||||||
{
|
{
|
||||||
if (args[0].equalsIgnoreCase("list"))
|
case 1:
|
||||||
{
|
if (args[0].equalsIgnoreCase("list"))
|
||||||
List<String> potionEffectTypeNames = new ArrayList<>();
|
|
||||||
for (PotionEffectType potion_effect_type : PotionEffectType.values())
|
|
||||||
{
|
{
|
||||||
if (potion_effect_type != null)
|
List<String> potionEffectTypeNames = new ArrayList<>();
|
||||||
|
for (PotionEffectType potion_effect_type : PotionEffectType.values())
|
||||||
{
|
{
|
||||||
potionEffectTypeNames.add(potion_effect_type.getName());
|
if (potion_effect_type != null)
|
||||||
|
{
|
||||||
|
potionEffectTypeNames.add(potion_effect_type.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
msg("Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
|
||||||
}
|
}
|
||||||
msg("Potion effect types: " + StringUtils.join(potionEffectTypeNames, ", "), ChatColor.AQUA);
|
else if (args[0].equalsIgnoreCase("clearall"))
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("clearall"))
|
|
||||||
{
|
|
||||||
if (!(plugin.sl.isStaff(sender) || senderIsConsole))
|
|
||||||
{
|
{
|
||||||
noPerms();
|
if (!(plugin.sl.isStaff(sender) || senderIsConsole))
|
||||||
return true;
|
|
||||||
}
|
|
||||||
FUtil.staffAction(sender.getName(), "Cleared all potion effects from all players", true);
|
|
||||||
for (Player target : server.getOnlinePlayers())
|
|
||||||
{
|
|
||||||
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
||||||
{
|
{
|
||||||
target.removePotionEffect(potion_effect.getType());
|
noPerms();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (args[0].equalsIgnoreCase("clear"))
|
|
||||||
{
|
|
||||||
Player target = playerSender;
|
|
||||||
|
|
||||||
if (args.length == 2)
|
FUtil.staffAction(sender.getName(), "Cleared all potion effects from all players", true);
|
||||||
|
for (Player target : server.getOnlinePlayers())
|
||||||
|
{
|
||||||
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
||||||
|
{
|
||||||
|
target.removePotionEffect(potion_effect.getType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (args[0].equalsIgnoreCase("clear"))
|
||||||
{
|
{
|
||||||
target = getPlayer(args[1], true);
|
Player target = playerSender;
|
||||||
|
if(args.length == 2)
|
||||||
|
{
|
||||||
|
if (!plugin.sl.isStaff(sender) && !target.equals(getPlayer(sender.getName())))
|
||||||
|
{
|
||||||
|
msg(ChatColor.RED + "Only staff can clear potion effects from other players.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
target = getPlayer(args[1], true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (senderIsConsole)
|
||||||
|
{
|
||||||
|
msg("You must specify a target player when using this command from the console.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (target == null)
|
if (target == null)
|
||||||
{
|
{
|
||||||
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (senderIsConsole)
|
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
||||||
{
|
|
||||||
msg("You must specify a target player when using this command from the console.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!plugin.sl.isStaff(sender))
|
|
||||||
{
|
|
||||||
msg(ChatColor.RED + "Only staff can clear potion effects from other players.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PotionEffect potion_effect : target.getActivePotionEffects())
|
|
||||||
{
|
|
||||||
target.removePotionEffect(potion_effect.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (args.length == 4 || args.length == 5)
|
|
||||||
{
|
|
||||||
if (args[0].equalsIgnoreCase("add"))
|
|
||||||
{
|
|
||||||
Player target = playerSender;
|
|
||||||
|
|
||||||
if (args.length == 5)
|
|
||||||
{
|
|
||||||
target = getPlayer(args[4]);
|
|
||||||
|
|
||||||
if (target == null || plugin.sl.isVanished(target.getName()) && !plugin.sl.isStaff(sender))
|
|
||||||
{
|
{
|
||||||
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
target.removePotionEffect(potion_effect.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
msg("Cleared all active potion effects " + (!target.equals(playerSender) ? "from player " + target.getName() + "." : "from yourself."), ChatColor.AQUA);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
case 5:
|
||||||
|
if (args[0].equalsIgnoreCase("add"))
|
||||||
|
{
|
||||||
|
Player target = playerSender;
|
||||||
|
|
||||||
|
if (args.length == 5)
|
||||||
|
{
|
||||||
|
if (!plugin.sl.isStaff(sender) && !getPlayer(args[4]).equals(getPlayer(sender.getName())))
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.RED + "Only staff can apply potion effects to other players.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
target = getPlayer(args[4]);
|
||||||
|
|
||||||
|
if (target == null || plugin.sl.isVanished(target.getName()) && !plugin.sl.isStaff(sender))
|
||||||
|
{
|
||||||
|
msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (senderIsConsole)
|
||||||
|
{
|
||||||
|
sender.sendMessage("You must specify a target player when using this command from the console.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
|
||||||
|
if (potion_effect_type == null)
|
||||||
|
{
|
||||||
|
sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (senderIsConsole)
|
int duration;
|
||||||
{
|
try
|
||||||
sender.sendMessage("You must specify a target player when using this command from the console.");
|
{
|
||||||
return true;
|
duration = Integer.parseInt(args[2]);
|
||||||
}
|
duration = Math.min(duration, 100000);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
msg("Invalid potion duration.", ChatColor.RED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!plugin.sl.isStaff(sender))
|
int amplifier;
|
||||||
{
|
try
|
||||||
sender.sendMessage(ChatColor.RED + "Only staff can apply potion effects to other players.");
|
{
|
||||||
return true;
|
amplifier = Integer.parseInt(args[3]);
|
||||||
}
|
amplifier = Math.min(amplifier, 100000);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
|
msg("Invalid potion amplifier.", ChatColor.RED);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
PotionEffectType potion_effect_type = PotionEffectType.getByName(args[1]);
|
PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
|
||||||
if (potion_effect_type == null)
|
target.addPotionEffect(new_effect, true);
|
||||||
{
|
msg(
|
||||||
sender.sendMessage(ChatColor.AQUA + "Invalid potion effect type.");
|
"Added potion effect: " + new_effect.getType().getName()
|
||||||
return true;
|
+ ", Duration: " + new_effect.getDuration()
|
||||||
|
+ ", Amplifier: " + new_effect.getAmplifier()
|
||||||
|
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
int duration;
|
default:
|
||||||
try
|
|
||||||
{
|
|
||||||
duration = Integer.parseInt(args[2]);
|
|
||||||
duration = Math.min(duration, 100000);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("Invalid potion duration.", ChatColor.RED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int amplifier;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
amplifier = Integer.parseInt(args[3]);
|
|
||||||
amplifier = Math.min(amplifier, 100000);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
msg("Invalid potion amplifier.", ChatColor.RED);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
PotionEffect new_effect = potion_effect_type.createEffect(duration, amplifier);
|
|
||||||
target.addPotionEffect(new_effect, true);
|
|
||||||
msg(
|
|
||||||
"Added potion effect: " + new_effect.getType().getName()
|
|
||||||
+ ", Duration: " + new_effect.getDuration()
|
|
||||||
+ ", Amplifier: " + new_effect.getAmplifier()
|
|
||||||
+ (!target.equals(playerSender) ? " to player " + target.getName() + "." : " to yourself."), ChatColor.AQUA);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -179,50 +175,54 @@ public class Command_potion extends FreedomCommand
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||||
{
|
{
|
||||||
if (args.length == 1)
|
switch (args.length)
|
||||||
{
|
{
|
||||||
List<String> arguments = new ArrayList<>();
|
case 1:
|
||||||
arguments.addAll(Arrays.asList("list", "clear", "add"));
|
List<String> arguments = new ArrayList<>();
|
||||||
if (plugin.sl.isStaff(sender))
|
arguments.addAll(Arrays.asList("list", "clear", "add"));
|
||||||
{
|
|
||||||
arguments.add("clearall");
|
|
||||||
}
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
else if (args.length == 2)
|
|
||||||
{
|
|
||||||
if (args[0].equals("clear"))
|
|
||||||
{
|
|
||||||
if (plugin.sl.isStaff(sender))
|
if (plugin.sl.isStaff(sender))
|
||||||
{
|
{
|
||||||
return FUtil.getPlayerList();
|
arguments.add("clearall");
|
||||||
}
|
}
|
||||||
}
|
return arguments;
|
||||||
else if (args[0].equals("add"))
|
|
||||||
{
|
case 2:
|
||||||
return getAllPotionTypes();
|
if (args[0].equals("clear"))
|
||||||
}
|
{
|
||||||
}
|
if (plugin.sl.isStaff(sender))
|
||||||
else if (args.length == 3)
|
{
|
||||||
{
|
return FUtil.getPlayerList();
|
||||||
if (args[0].equals("add"))
|
}
|
||||||
{
|
}
|
||||||
return Arrays.asList("<duration>");
|
else if (args[0].equals("add"))
|
||||||
}
|
{
|
||||||
}
|
return getAllPotionTypes();
|
||||||
else if (args.length == 4)
|
}
|
||||||
{
|
break;
|
||||||
if (args[0].equals("add"))
|
|
||||||
{
|
case 3:
|
||||||
return Arrays.asList("<amplifier>");
|
if (args[0].equals("add"))
|
||||||
}
|
{
|
||||||
}
|
return Arrays.asList("<duration>");
|
||||||
else if (args.length == 5 && plugin.sl.isStaff(sender))
|
}
|
||||||
{
|
break;
|
||||||
if (args[0].equals("add"))
|
|
||||||
{
|
case 4:
|
||||||
return FUtil.getPlayerList();
|
if (args[0].equals("add"))
|
||||||
}
|
{
|
||||||
|
return Arrays.asList("<amplifier>");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
if (plugin.sl.isStaff(sender))
|
||||||
|
{
|
||||||
|
if (args[0].equals("add"))
|
||||||
|
{
|
||||||
|
return FUtil.getPlayerList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
@ -2,6 +2,6 @@ name: TotalFreedomMod
|
|||||||
main: me.totalfreedom.totalfreedommod.TotalFreedomMod
|
main: me.totalfreedom.totalfreedommod.TotalFreedomMod
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
description: Plugin for the Total Freedom server.
|
description: Plugin for the Total Freedom server.
|
||||||
loadbefore: [BukkitTelnet, Essentials, LibsDisguises, WorldEdit, WorldGuard, WorldGuardExtraFlags, TFGuilds, SuperVanish, PremiumVanish]
|
loadbefore: [BukkitTelnet, Essentials, CoreProtect, LibsDisguises, WorldEdit, WorldGuard, WorldGuardExtraFlags, TFGuilds, SuperVanish, PremiumVanish]
|
||||||
authors: [Madgeek1450, Prozza]
|
authors: [Madgeek1450, Prozza]
|
||||||
api-version: 1.16
|
api-version: 1.16
|
Loading…
Reference in New Issue
Block a user