Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.redcastlemedia.multitallented.civs.regions.Region;
import org.redcastlemedia.multitallented.civs.items.CVItem;
import org.redcastlemedia.multitallented.civs.regions.Region;

import java.io.File;
import java.io.IOException;
Expand All @@ -14,7 +14,7 @@
@CivsSingleton(priority = CivsSingleton.SingletonLoadPriority.HIGH)
public class BlockLogger {
private static BlockLogger blockLogger = null;
private HashMap<String, CVItem> blocks = new HashMap<>();
private final HashMap<String, CVItem> blocks = new HashMap<>();

// private long lastSave = 0;
// private int intervalId = -1;
Expand Down Expand Up @@ -65,24 +65,20 @@ private void saveBlocks() {
}
final File blockData = new File(Civs.dataLocation, "block-data.yml");
final HashMap<String, CVItem> finalBlocks = blocks;
Runnable runMe = new Runnable() {
@Override
public void run() {
FileConfiguration config = new YamlConfiguration();
try {
//Don't load the file. Overwrite it
for (String location : finalBlocks.keySet()) {
CVItem cvItem = finalBlocks.get(location);
String locationString = location.replaceAll("\\.", "^");
config.set(locationString + ".mat", cvItem.getMat().toString());
config.set(locationString + ".name", cvItem.getDisplayName());
config.set(locationString + ".lore", cvItem.getLore());
}
config.save(blockData);
} catch (Exception e) {
Civs.logger.severe("Unable to save to block-data.yml");
return;
Runnable runMe = () -> {
FileConfiguration config = new YamlConfiguration();
try {
//Don't load the file. Overwrite it
for (String location : finalBlocks.keySet()) {
CVItem cvItem = finalBlocks.get(location);
String locationString = location.replaceAll("\\.", "^");
config.set(locationString + ".mat", cvItem.getMat().toString());
config.set(locationString + ".name", cvItem.getDisplayName());
config.set(locationString + ".lore", cvItem.getLore());
}
config.save(blockData);
} catch (Exception e) {
Civs.logger.severe("Unable to save to block-data.yml");
}
};
runMe.run();
Expand Down Expand Up @@ -117,13 +113,11 @@ private void loadBlocks() {
} catch (Exception e) {
Civs.logger.severe("Unable to read line from block-data.yml");
e.printStackTrace();
continue;
}
}

} catch (Exception e) {
Civs.logger.severe("Unable to read from block-data.yml");
return;
}
}

Expand Down
29 changes: 10 additions & 19 deletions src/main/java/org/redcastlemedia/multitallented/civs/Civs.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import org.redcastlemedia.multitallented.civs.civilians.allowedactions.AllowedActionsListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.redcastlemedia.multitallented.civs.civilians.allowedactions.AllowedActionsListener;
import org.redcastlemedia.multitallented.civs.commands.CivCommand;
import org.redcastlemedia.multitallented.civs.commands.CivsCommand;
import org.redcastlemedia.multitallented.civs.commands.TabComplete;
import org.redcastlemedia.multitallented.civs.dynmaphook.DynmapHook;
import org.redcastlemedia.multitallented.civs.placeholderexpansion.PlaceHook;
import org.redcastlemedia.multitallented.civs.regions.RegionManager;
import org.redcastlemedia.multitallented.civs.regions.StructureUtil;
import org.redcastlemedia.multitallented.civs.regions.effects.ConveyorEffect;
import org.redcastlemedia.multitallented.civs.scheduler.CommonScheduler;
import org.redcastlemedia.multitallented.civs.scheduler.DailyScheduler;
Expand All @@ -52,7 +55,7 @@
public class Civs extends JavaPlugin {

public static File dataLocation;
private HashMap<String, CivCommand> commandList = new HashMap<>();
private final HashMap<String, CivCommand> commandList = new HashMap<>();
public static final String NAME = "Civs";
public static Economy econ;
public static Permission perm;
Expand Down Expand Up @@ -159,13 +162,9 @@ private void initScheduler() {
CommonScheduler commonScheduler = new CommonScheduler();
getServer().getScheduler().scheduleSyncRepeatingTask(this, commonScheduler, 4L, 4L);

getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

@Override
public void run() {
RegionManager.getInstance().saveNextRegion();
TownManager.getInstance().saveNextTown();
}
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
RegionManager.getInstance().saveNextRegion();
TownManager.getInstance().saveNextTown();
}, 20L, 20L);
}

Expand Down Expand Up @@ -241,19 +240,11 @@ private void instantiateSingletons() {
Reflections reflections = new Reflections(configurationBuilder);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(CivsSingleton.class);
List<Class<?>> classList = new ArrayList<>(classes);
classList.sort(new Comparator<Class<?>>() {
@Override
public int compare(Class<?> o1, Class<?> o2) {
return o1.getAnnotation(CivsSingleton.class).priority().compareTo(o2.getAnnotation(CivsSingleton.class).priority());
}
});
classList.sort(Comparator.comparing(o -> o.getAnnotation(CivsSingleton.class).priority()));
for (Class<?> currentSingleton : classList) {
try {
Method method = currentSingleton.getMethod("getInstance");
if (method != null) {
method.invoke(currentSingleton);
}
} catch (Exception e) {
currentSingleton.getMethod("getInstance").invoke(currentSingleton);
} catch (Exception ignored) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface CivsSingleton {
public SingletonLoadPriority priority() default SingletonLoadPriority.MEDIUM;
SingletonLoadPriority priority() default SingletonLoadPriority.MEDIUM;

public enum SingletonLoadPriority {
enum SingletonLoadPriority {
CRITICAL(100),
HIGHEST(99),
HIGHER(80),
Expand All @@ -19,7 +19,7 @@ public enum SingletonLoadPriority {
LOW(25),
LOWEST(1);

private int value;
private final int value;
public int getValue() {
return this.value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.redcastlemedia.multitallented.civs;

import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.redcastlemedia.multitallented.civs.chat.ChatChannelConfig;
import org.redcastlemedia.multitallented.civs.civilians.ChatChannel;
import org.redcastlemedia.multitallented.civs.towns.GovernmentType;
import org.redcastlemedia.multitallented.civs.items.CVItem;
import org.redcastlemedia.multitallented.civs.towns.GovernmentType;
import org.redcastlemedia.multitallented.civs.util.FallbackConfigUtil;
import org.redcastlemedia.multitallented.civs.util.Util;

import java.io.File;
import java.util.*;
import java.util.logging.Level;

import lombok.Getter;

@CivsSingleton(priority = CivsSingleton.SingletonLoadPriority.CRITICAL)
public class ConfigManager {
private static final String CONFIG_FILE_NAME = "config.yml";
Expand Down Expand Up @@ -300,7 +299,7 @@ private void loadFile(File configFile) {
ConfigurationSection section2 = config.getConfigurationSection("folders");
if (section2 != null) {
for (String key : section2.getKeys(false)) {
String iconString = "CHEST";
String iconString;
if (config.isSet("folders." + key + ".icon")) {
iconString = config.getString("folders." + key + ".icon", "CHEST");
} else {
Expand Down
42 changes: 14 additions & 28 deletions src/main/java/org/redcastlemedia/multitallented/civs/ai/AI.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package org.redcastlemedia.multitallented.civs.ai;

import java.util.UUID;

import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.redcastlemedia.multitallented.civs.Civs;
import org.redcastlemedia.multitallented.civs.localization.LocaleManager;
import org.redcastlemedia.multitallented.civs.civilians.Civilian;
import org.redcastlemedia.multitallented.civs.civilians.CivilianManager;
import org.redcastlemedia.multitallented.civs.localization.LocaleManager;
import org.redcastlemedia.multitallented.civs.towns.Town;
import org.redcastlemedia.multitallented.civs.towns.TownManager;
import org.redcastlemedia.multitallented.civs.util.Constants;

import lombok.Getter;
import java.util.UUID;

@Getter
public class AI {
private final String townName;
private Town town;
private final Town town;

public AI(String townName) {
this.townName = townName;
Expand Down Expand Up @@ -113,34 +112,21 @@ private boolean invitePlayer(Player player) {

String[] args = new String[1];
args[0] = player.getDisplayName();
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() {
@Override
public void run() {
broadcastToAllPlayers("ai-invite", args, getDisplayName());
}
}, 100);
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() {
@Override
public void run() {
Civilian inviteCiv = CivilianManager.getInstance().getCivilian(player.getUniqueId());

if (TownManager.getInstance().addInvite(player.getUniqueId(), town)) {
player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(player,
"invite-player").replace("$1", getDisplayName() + ChatColor.GREEN)
.replace("$2", town.getType())
.replace("$3", townName));
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), () -> broadcastToAllPlayers("ai-invite", args, getDisplayName()), 100);
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), () -> {
Civilian inviteCiv = CivilianManager.getInstance().getCivilian(player.getUniqueId());

if (TownManager.getInstance().addInvite(player.getUniqueId(), town)) {
player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(player,
"invite-player").replace("$1", getDisplayName() + ChatColor.GREEN)
.replace("$2", town.getType())
.replace("$3", townName));
}
}, 120);

String[] args2 = new String[1];
args2[0] = Bukkit.getPlayer(uuid).getDisplayName();
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), new Runnable() {
@Override
public void run() {
broadcastToAllPlayers("ai-help", args2, getDisplayName());
}
}, 130);
Bukkit.getScheduler().scheduleSyncDelayedTask(Civs.getInstance(), () -> broadcastToAllPlayers("ai-help", args2, getDisplayName()), 130);

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.redcastlemedia.multitallented.civs.ai;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.redcastlemedia.multitallented.civs.Civs;

import lombok.Getter;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

public class AIManager {
private HashMap<String, AI> ais = new HashMap<>();
private final HashMap<String, AI> ais = new HashMap<>();
@Getter
private HashMap<Player, AI> chatHandler = new HashMap<>();
private final HashMap<Player, AI> chatHandler = new HashMap<>();

private static AIManager instance = null;
public static AIManager getInstance() {
Expand Down Expand Up @@ -44,7 +43,6 @@ private void loadAIs() {
}
} catch (NullPointerException npe) {
Civs.logger.severe("Unable to create ai folder");
return;
}
}

Expand Down Expand Up @@ -84,7 +82,6 @@ public void saveAI(AI ai) {
config.save(aiFile);
} catch (Exception e) {
Civs.logger.severe("Unable to save ai file " + ai.getTownName() + ".yml");
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ private void loadAlliance(File allianceFile) {
config.load(allianceFile);
Alliance alliance = new Alliance();
alliance.setName(allianceFile.getName().replace(".yml", ""));
alliance.setMembers(new HashSet<String>(config.getStringList("members")));
for (String townName : new ArrayList<>(alliance.getMembers())) {
if (TownManager.getInstance().getTown(townName) == null) {
alliance.getMembers().remove(townName);
}
}
alliance.setMembers(new HashSet<>(config.getStringList("members")));
alliance.getMembers().removeIf(townName -> TownManager.getInstance().getTown(townName) == null);
String uuidString = config.getString("last-rename", null);
if (uuidString != null) {
alliance.setLastRenamedBy(UUID.fromString(uuidString));
Expand Down Expand Up @@ -126,7 +122,7 @@ public void saveAlliance(Alliance alliance) {
allianceFile.createNewFile();
}
FileConfiguration config = new YamlConfiguration();
config.set("members", new ArrayList<String>(alliance.getMembers()));
config.set("members", new ArrayList<>(alliance.getMembers()));
if (alliance.getLastRenamedBy() != null) {
config.set("last-rename", alliance.getLastRenamedBy().toString());
}
Expand Down Expand Up @@ -325,13 +321,10 @@ public void onTownDestroyed(TownDestroyedEvent event) {

public ArrayList<Alliance> getAllSortedAlliances() {
ArrayList<Alliance> returnList = getAllAlliances();
Comparator<Alliance> comparator = new Comparator<Alliance>() {
@Override
public int compare(Alliance o1, Alliance o2) {
int o1Size = o1.getMembers().size();
int o2Size = o2.getMembers().size();
return Integer.compare(o1Size, o2Size);
}
Comparator<Alliance> comparator = (o1, o2) -> {
int o1Size = o1.getMembers().size();
int o2Size = o2.getMembers().size();
return Integer.compare(o1Size, o2Size);
};
returnList.sort(comparator);
return returnList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ public static Set<HackType> mapExemptionTypeToHackTypes(ExemptionType exemptionT
Set<HackType> hackTypes = new HashSet<>();
switch (exemptionType) {
case FLY:
case JESUS:
hackTypes.add(HackType.MOVE);
break;
case FALL:
hackTypes.add(HackType.NOFALL);
break;
case JESUS:
hackTypes.add(HackType.MOVE);
break;
case KILL_AURA:
hackTypes.add(HackType.CRITICALS);
hackTypes.add(HackType.FIGHTSPEED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ public static Set<CheckType> mapExemptionTypeToCheatTypes(ExemptionType exemptio
Set<CheckType> checks = new HashSet<>();
switch (exemptionType) {
case FLY:
case JESUS:
checks.add(CheckType.MOVING_SURVIVALFLY);
checks.add(CheckType.MOVING);
break;
case FALL:
checks.add(CheckType.MOVING_NOFALL);
break;
case JESUS:
checks.add(CheckType.MOVING_SURVIVALFLY);
checks.add(CheckType.MOVING);
break;
case KILL_AURA:
checks.add(CheckType.FIGHT);
break;
Expand Down
Loading