kuper kant kode

This commit is contained in:
ZeroEpoch1969 2020-01-09 18:02:28 -07:00
parent cf21b8d07e
commit f989b34ada
No known key found for this signature in database
GPG Key ID: A7BAB4E14F089CF3
3 changed files with 174 additions and 24 deletions

View File

@ -1,9 +1,12 @@
package me.totalfreedom.totalfreedommod; package me.totalfreedom.totalfreedommod;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.Groups;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -16,29 +19,34 @@ public class EntityWiper extends FreedomService
super(plugin); super(plugin);
} }
public List<EntityType> BLACKLIST = Arrays.asList(
EntityType.ARMOR_STAND,
EntityType.PAINTING,
EntityType.BOAT,
EntityType.PLAYER,
EntityType.LEASH_HITCH,
EntityType.ITEM_FRAME
);
@Override @Override
protected void onStart() protected void onStart()
{ {
BLACKLIST.addAll(Groups.MOB_TYPES);
// Continuous Entity Wiper // Continuous Entity Wiper
wiper = new BukkitRunnable() wiper = new BukkitRunnable()
{ {
@Override @Override
public void run() public void run()
{ {
for (World world : Bukkit.getWorlds()) wipe();
{
if (world.getEntities().size() > 400)
{
world.getEntities().clear();
}
}
} }
}.runTaskTimer(plugin, 0, 1); }.runTaskTimer(plugin, 1L, 300 * 5); // 5 minutes
} }
@Override @Override
protected void onStop() protected void onStop()
{ {
BLACKLIST.removeAll(Groups.MOB_TYPES);
wiper.cancel(); wiper.cancel();
wiper = null; wiper = null;
} }
@ -52,7 +60,7 @@ public class EntityWiper extends FreedomService
{ {
for (Entity entity : world.getEntities()) for (Entity entity : world.getEntities())
{ {
if (!(entity instanceof Player)) if (!BLACKLIST.contains(entity.getType()))
{ {
entity.remove(); entity.remove();
removed++; removed++;
@ -61,18 +69,4 @@ public class EntityWiper extends FreedomService
} }
return removed; return removed;
} }
public int wipe(World world)
{
int removed = 0;
for (Entity entity : world.getEntities())
{
if (!(entity instanceof Player))
{
entity.remove();
removed++;
}
}
return removed;
}
} }

View File

@ -0,0 +1,89 @@
package me.totalfreedom.totalfreedommod.command;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.HashMap;
import java.util.Map;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Make a region for an OP.", usage = "/<command> <playername> <name>", aliases = "mor")
public class Command_makeopregion extends FreedomCommand
{
final Map<Flag<?>, Object> flags = new HashMap<Flag<?>, Object>() {{
put(Flags.BLOCK_PLACE, StateFlag.State.DENY);
put(Flags.BLOCK_BREAK, StateFlag.State.DENY);
put(Flags.BUILD, StateFlag.State.DENY);
put(Flags.PLACE_VEHICLE, StateFlag.State.DENY);
put(Flags.DESTROY_VEHICLE, StateFlag.State.DENY);
put(Flags.ENTITY_ITEM_FRAME_DESTROY, StateFlag.State.DENY);
put(Flags.ENTITY_PAINTING_DESTROY, StateFlag.State.DENY);
}};
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
if (args.length < 2)
{
return false;
}
final Player player = getPlayer(args[0]);
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
String name = args[1];
LocalSession session = plugin.web.getWorldEditPlugin().getSession(playerSender);
Region selection = null;
try
{
selection = session.getSelection(session.getSelectionWorld());
}
catch (IncompleteRegionException e)
{
msg("Please make a WorldEdit selection", ChatColor.RED);
return true;
}
if (selection == null)
{
msg("Please make a WorldEdit selection", ChatColor.RED);
return true;
}
ProtectedRegion region = new ProtectedCuboidRegion(name, selection.getMinimumPoint(), selection.getMaximumPoint());
DefaultDomain owners = new DefaultDomain();
owners.addPlayer(playerSender.getName());
owners.addPlayer(player.getName());
region.setOwners(owners);
region.setFlags(flags);
RegionManager regionManager = plugin.wgb.getWorldGuardPlugin().getRegionManager(playerSender.getWorld());
regionManager.addRegion(region);
msg("Successfully created the region '" + name + "' for " + player.getName(), ChatColor.GREEN);
return true;
}
}

View File

@ -0,0 +1,67 @@
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Stop playing sounds", usage = "/<command> [sound]")
public class Command_stopsound extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0)
{
Sound sound = Sound.valueOf(args[0].toUpperCase());
if (sound != null)
{
playerSender.stopSound(sound);
msg("Stopped all " + sound.name() + " sounds", ChatColor.GREEN);
}
else
{
msg(args[0] + " is not a valid sound.", ChatColor.RED);
}
}
else
{
for (Sound sound : Sound.values())
{
playerSender.stopSound(sound);
}
msg("Stopped all sounds.", ChatColor.GREEN);
}
return true;
}
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (args.length == 1)
{
return soundList();
}
return Collections.emptyList();
}
public List<String> soundList()
{
List<String> sounds = new ArrayList<>();
for (Sound sound : Sound.values())
{
sounds.add(sound.name());
}
return sounds;
}
}