mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 06:38:56 +00:00
Update for 1.19
This commit is contained in:
@@ -11,7 +11,6 @@ import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.PermissionUtil;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.apache.commons.lang.mutable.MutableInt;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -32,7 +31,7 @@ import java.util.*;
|
||||
|
||||
public class BPlayer {
|
||||
private static Map<String, BPlayer> players = new HashMap<>();// Players uuid and BPlayer
|
||||
private static Map<Player, MutableInt> pTasks = new HashMap<>();// Player and count
|
||||
private static Map<Player, Integer> pTasks = new HashMap<>();// Player and count
|
||||
private static int taskId;
|
||||
private static Random pukeRand;
|
||||
|
||||
@@ -576,21 +575,22 @@ public class BPlayer {
|
||||
if (pTasks.isEmpty()) {
|
||||
taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, BPlayer::pukeTask, 1L, 1L);
|
||||
}
|
||||
pTasks.put(player, new MutableInt(event.getCount()));
|
||||
pTasks.put(player, event.getCount());
|
||||
}
|
||||
|
||||
public static void pukeTask() {
|
||||
for (Iterator<Map.Entry<Player, MutableInt>> iter = pTasks.entrySet().iterator(); iter.hasNext(); ) {
|
||||
Map.Entry<Player, MutableInt> entry = iter.next();
|
||||
for (Iterator<Map.Entry<Player, Integer>> iter = pTasks.entrySet().iterator(); iter.hasNext(); ) {
|
||||
Map.Entry<Player, Integer> entry = iter.next();
|
||||
Player player = entry.getKey();
|
||||
MutableInt count = entry.getValue();
|
||||
int count = entry.getValue();
|
||||
if (!player.isValid() || !player.isOnline()) {
|
||||
iter.remove();
|
||||
}
|
||||
puke(player);
|
||||
count.decrement();
|
||||
if (count.intValue() <= 0) {
|
||||
if (count <= 1) {
|
||||
iter.remove();
|
||||
} else {
|
||||
entry.setValue(count - 1);
|
||||
}
|
||||
}
|
||||
if (pTasks.isEmpty()) {
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.dre.brewery.recipe.*;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.LegacyUtil;
|
||||
import com.dre.brewery.utility.Stats;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -331,9 +330,39 @@ public class P extends JavaPlugin {
|
||||
}
|
||||
|
||||
public int parseInt(String string) {
|
||||
return NumberUtils.toInt(string, 0);
|
||||
if (string == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(string);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double parseDouble(String string) {
|
||||
if (string == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(string);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public float parseFloat(String string) {
|
||||
if (string == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(string);
|
||||
} catch (NumberFormatException ignored) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String color(String msg) {
|
||||
return BUtil.color(msg);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.dre.brewery.recipe.BCauldronRecipe;
|
||||
import com.dre.brewery.recipe.BRecipe;
|
||||
import com.dre.brewery.Barrel;
|
||||
import com.dre.brewery.Brew;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
@@ -356,7 +355,7 @@ public class BreweryApi {
|
||||
public static void addRecipe(BRecipe recipe, boolean saveForever) {
|
||||
//recipe.setSaveInData(saveForever);
|
||||
if (saveForever) {
|
||||
throw new NotImplementedException("SaveForever is not implemented yet");
|
||||
throw new UnsupportedOperationException("SaveForever is not implemented yet");
|
||||
}
|
||||
BRecipe.getAddedRecipes().add(recipe);
|
||||
recipe.updateAcceptedLists();
|
||||
@@ -424,7 +423,7 @@ public class BreweryApi {
|
||||
public static void addCauldronRecipe(BCauldronRecipe recipe, boolean saveForever) {
|
||||
//recipe.setSaveInData(saveForever);
|
||||
if (saveForever) {
|
||||
throw new NotImplementedException();
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
BCauldronRecipe.getAddedRecipes().add(recipe);
|
||||
recipe.updateAcceptedLists();
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.dre.brewery.recipe.PluginItem;
|
||||
import com.dre.brewery.recipe.SimpleItem;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.BoundingBox;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -24,6 +22,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BData {
|
||||
|
||||
@@ -363,7 +362,7 @@ public class BData {
|
||||
if (woLength > 1) {
|
||||
System.arraycopy(wo, 0, points, st.length, woLength);
|
||||
}
|
||||
int[] locs = ArrayUtils.toPrimitive(Arrays.stream(points).map(s -> P.p.parseInt(s)).toArray(Integer[]::new));
|
||||
int[] locs = Arrays.stream(points).mapToInt(s -> P.p.parseInt(s)).toArray();
|
||||
try {
|
||||
box = BoundingBox.fromPoints(locs);
|
||||
} catch (Exception e) {
|
||||
@@ -406,11 +405,11 @@ public class BData {
|
||||
String[] splitted = loc.split("/");
|
||||
if (splitted.length == 5) {
|
||||
|
||||
double x = NumberUtils.toDouble(splitted[0]);
|
||||
double y = NumberUtils.toDouble(splitted[1]);
|
||||
double z = NumberUtils.toDouble(splitted[2]);
|
||||
float pitch = NumberUtils.toFloat(splitted[3]);
|
||||
float yaw = NumberUtils.toFloat(splitted[4]);
|
||||
double x = P.p.parseDouble(splitted[0]);
|
||||
double y = P.p.parseDouble(splitted[1]);
|
||||
double z = P.p.parseDouble(splitted[2]);
|
||||
float pitch = P.p.parseFloat(splitted[3]);
|
||||
float yaw = P.p.parseFloat(splitted[4]);
|
||||
Location location = new Location(world, x, y, z, yaw, pitch);
|
||||
|
||||
initWakeups.add(new Wakeup(location));
|
||||
|
||||
@@ -81,11 +81,8 @@ public class UpdateChecker implements Runnable {
|
||||
// Read the response of the query
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
JsonParser parser = new JsonParser();
|
||||
|
||||
|
||||
// Parse the array of files from the query's response
|
||||
JsonArray array = parser.parse(reader).getAsJsonArray();
|
||||
JsonArray array = JsonParser.parseReader(reader).getAsJsonArray();
|
||||
|
||||
if (array.size() > 0) {
|
||||
// Get the newest file's details
|
||||
|
||||
@@ -6,18 +6,24 @@ import com.dre.brewery.api.events.barrel.BarrelAccessEvent;
|
||||
import com.palmergames.bukkit.towny.TownySettings;
|
||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class TownyBarrel {
|
||||
public static boolean checkAccess(BarrelAccessEvent event) {
|
||||
if (!TownySettings.isSwitchMaterial("BREWERY") && !TownySettings.isSwitchMaterial("BARREL")) {
|
||||
if (P.use1_14) {
|
||||
Location barrelLoc = event.getSpigot().getLocation();
|
||||
Material mat = P.use1_14 ? Material.BARREL : Material.CHEST;
|
||||
|
||||
try {
|
||||
if (!TownySettings.isSwitchMaterial(mat, barrelLoc)) {
|
||||
return true;
|
||||
} else if (!TownySettings.isSwitchMaterial("CHEST")) {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//noinspection deprecation
|
||||
if (!TownySettings.isSwitchMaterial("CHEST")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Material mat = P.use1_14 ? Material.BARREL : Material.CHEST;
|
||||
return PlayerCacheUtil.getCachePermission(event.getPlayer(), event.getSpigot().getLocation(), mat, TownyPermission.ActionType.SWITCH);
|
||||
return PlayerCacheUtil.getCachePermission(event.getPlayer(), barrelLoc, mat, TownyPermission.ActionType.SWITCH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.dre.brewery.filedata.BConfig;
|
||||
import com.dre.brewery.utility.BUtil;
|
||||
import com.dre.brewery.utility.StringParser;
|
||||
import com.dre.brewery.utility.Tuple;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -717,7 +716,7 @@ public class BRecipe {
|
||||
}
|
||||
|
||||
public void setSaveInData(boolean saveInData) {
|
||||
throw new NotImplementedException();
|
||||
throw new UnsupportedOperationException();
|
||||
//this.saveInData = saveInData;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dre.brewery.utility;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permissible;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
@@ -125,10 +124,12 @@ public class PermissionUtil {
|
||||
if (found.isPresent()) {
|
||||
String permission = found.get().getPermission();
|
||||
int lastDot = permission.lastIndexOf('.');
|
||||
int value = NumberUtils.toInt(permission.substring(lastDot + 1), -1);
|
||||
if (value >= 0) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
int value = Integer.parseInt(permission.substring(lastDot + 1));
|
||||
if (value >= 0) {
|
||||
return value;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user