Removes useless code

This commit is contained in:
Video 2022-04-15 05:03:41 -06:00
parent adcccb10e5
commit c39c632a67
7 changed files with 14 additions and 207 deletions

View File

@ -114,8 +114,7 @@ public class EssentialsBridge extends FreedomService
User user = getEssentialsUser(username);
if (user != null)
{
Long l = FUtil.getField(user, "lastActivity");
return (l != null) ? l : 0L;
return user.getLastOnlineActivity();
}
}
catch (Exception ex)

View File

@ -48,52 +48,6 @@ public class WorldEditBridge extends FreedomService
return worldeditPlugin;
}
public void undo(Player player, int count)
{
try
{
LocalSession session = getPlayerSession(player);
if (session != null)
{
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
if (bukkitPlayer != null)
{
for (int i = 0; i < count; i++)
{
session.undo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
}
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
public void redo(Player player, int count)
{
try
{
LocalSession session = getPlayerSession(player);
if (session != null)
{
final BukkitPlayer bukkitPlayer = getBukkitPlayer(player);
if (bukkitPlayer != null)
{
for (int i = 0; i < count; i++)
{
session.redo(session.getBlockBag(bukkitPlayer), bukkitPlayer);
}
}
}
}
catch (Exception ex)
{
FLog.severe(ex);
}
}
public void setLimit(Player player, int limit)
{
try
@ -153,23 +107,4 @@ public class WorldEditBridge extends FreedomService
return null;
}
}
private BukkitPlayer getBukkitPlayer(Player player)
{
final WorldEditPlugin wep = getWorldEditPlugin();
if (wep == null)
{
return null;
}
try
{
return wep.wrapPlayer(player);
}
catch (Exception ex)
{
FLog.severe(ex);
return null;
}
}
}

View File

@ -1,19 +1,12 @@
package me.totalfreedom.totalfreedommod.bridge;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import java.util.Map;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import me.totalfreedom.totalfreedommod.FreedomService;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -22,7 +15,6 @@ public class WorldGuardBridge extends FreedomService
@Override
public void onStart()
{
plugin.wr.protectWorld(plugin.wm.masterBuilderWorld.getWorld());
}
@Override
@ -32,34 +24,19 @@ public class WorldGuardBridge extends FreedomService
public boolean canEditCurrentWorld(Player player)
{
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
return query.testBuild(localPlayer.getLocation(), localPlayer);
}
public RegionManager getRegionManager(World world)
{
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
return container.get(BukkitAdapter.adapt(world));
}
public int wipeRegions(World world)
{
int count = 0;
RegionManager regionManager = getRegionManager(world);
if (regionManager != null)
// If WorldGuard integration is enabled, do a check with it.
if (isEnabled())
{
Map<String, ProtectedRegion> regions = regionManager.getRegions();
for (ProtectedRegion region : regions.values())
{
regionManager.removeRegion(region.getId());
count++;
}
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
return query.testBuild(localPlayer.getLocation(), localPlayer);
}
return count;
// If the plugin isn't present, return true.
return true;
}
public boolean isEnabled()

View File

@ -5,7 +5,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -95,7 +94,7 @@ public class Command_whitelist extends FreedomCommand
if (player == null)
{
player = DepreciationAggregator.getOfflinePlayer(server, search_name);
player = server.getOfflinePlayer(search_name);
}
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the whitelist", false);
@ -117,7 +116,7 @@ public class Command_whitelist extends FreedomCommand
if (player == null)
{
player = DepreciationAggregator.getOfflinePlayer(server, search_name);
player = server.getOfflinePlayer(search_name);
}
if (player.isWhitelisted())

View File

@ -1,28 +0,0 @@
package me.totalfreedom.totalfreedommod.util;
import java.util.HashSet;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@SuppressWarnings("deprecation")
public class DepreciationAggregator
{
public static Block getTargetBlock(LivingEntity entity, HashSet<Material> transparent, int maxDistance)
{
return entity.getTargetBlock(transparent, maxDistance);
}
public static OfflinePlayer getOfflinePlayer(Server server, String name)
{
return server.getOfflinePlayer(name);
}
public static String getName_EntityType(EntityType et)
{
return et.getName();
}
}

View File

@ -225,33 +225,6 @@ public class FUtil
return names;
}
@SuppressWarnings("unchecked")
public static UUID nameToUUID(String name)
{
try
{
JSONArray json = new JSONArray();
json.add(name);
List<String> headers = new ArrayList<>();
headers.add("Accept:application/json");
headers.add("Content-Type:application/json");
Response response = sendRequest("https://api.mojang.com/profiles/minecraft", "POST", headers, json.toString());
// Don't care how stupid this looks, couldn't find anything to parse a json string to something readable in java with something not horrendously huge, maybe im just retarded
Pattern pattern = Pattern.compile("(?<=\"id\":\")[a-f0-9].{31}");
Matcher matcher = pattern.matcher(response.getMessage());
if (matcher.find())
{
String rawUUID = matcher.group(0).replaceFirst("([a-f0-9]{8})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]{4})([a-f0-9]+)", "$1-$2-$3-$4-$5");
return UUID.fromString(rawUUID);
}
}
catch (Exception e)
{
FLog.severe("Failed to convert name to UUID:\n" + e.toString());
}
return null;
}
public static Response sendRequest(String endpoint, String method, List<String> headers, String body) throws IOException
{
URL url = new URL(endpoint);
@ -537,30 +510,6 @@ public class FUtil
return ip;
}
//getField: Borrowed from WorldEdit
@SuppressWarnings("unchecked")
public static <T> T getField(Object from, String name)
{
Class<?> checkClass = from.getClass();
do
{
try
{
Field field = checkClass.getDeclaredField(name);
field.setAccessible(true);
return (T) field.get(from);
}
catch (NoSuchFieldException | IllegalAccessException ignored)
{
}
}
while (checkClass.getSuperclass() != Object.class
&& ((checkClass = checkClass.getSuperclass()) != null));
return null;
}
public static ChatColor randomChatColor()
{
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));

View File

@ -32,14 +32,6 @@ public class WorldRestrictions extends FreedomService
private final List<String> BLOCKED_ESSENTIALS_COMMANDS = Arrays.asList(
"bigtree", "ebigtree", "largetree", "elargetree");
private final Map<Flag<?>, Object> flags = new HashMap<Flag<?>, Object>()
{{
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);
}};
@Override
public void onStart()
{
@ -155,20 +147,4 @@ public class WorldRestrictions extends FreedomService
}
}
}
public void protectWorld(World world)
{
if (!plugin.wgb.isEnabled())
{
return;
}
RegionManager regionManager = plugin.wgb.getRegionManager(world);
GlobalProtectedRegion region = new GlobalProtectedRegion("__global__");
region.setFlags(flags);
regionManager.addRegion(region);
}
}