Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[challenges] Minecraft by Ruby #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
@@ -0,0 +1,41 @@
package org.abc.A.B;

import lombok.AllArgsConstructor;
import org.abc.A.N.DisplayItem;
import org.abc.A.N.DisplayType;
import org.abc.A.N.Shop;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.abc.A.QuickShop;

@AllArgsConstructor
public class DisplayItemAPI {
private QuickShop plugin;

/**
* Checks is a display item
* @param itemStack The itemstack
* @return yes or no
*/
public static boolean isDisplayItem(@NotNull ItemStack itemStack){
return DisplayItem.checkIsGuardItemStack(itemStack);
}

/**
* Check is a shop's display item
* @param itemStack The itemstack
* @param shop The itemstack
* @return yes or no
*/
public static boolean isShopDisplayItem(@NotNull ItemStack itemStack, @NotNull Shop shop){
return DisplayItem.checkIsTargetShopDisplay(itemStack,shop);
}

/**
* Gets the display type now using
* @return The type of display now using
*/
public static DisplayType getNowUsing(){
return DisplayItem.getNowUsing();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.abc.A.B;

import org.abc.A.util.IntegrationHelper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.abc.A.QuickShop;
import org.abc.A.util.compatibility.CompatibilityManager;

public class QuickShopAPI {
private static QuickShop plugin;

/**
* DO NOT CALL ME, IT JUST A INTERNAL METHOD, BUT BECAUSE CROSS-PACKAGE ACCESS, IT IS PUBLIC, SO DO NOT EXECUTE IT.
* Go away =w=
* @param qs The QuickShop plugin instance
*/
public static void setupApi(@NotNull QuickShop qs){
plugin = qs;
}

/**
* Gets apis about shop
* @return The Shop API
*/
public static @NotNull ShopAPI getShopAPI(){
return new ShopAPI(plugin);
}

/**
* Gets apis about display item
* @return The DisplayItem API
*/
public static @NotNull DisplayItemAPI getDisplayItemAPI(){
return new DisplayItemAPI(plugin);
}

/**
* Gets anti-cheat compatibility manager to allow you access and process.
* If you calling this before plugin loaded up, you might get nothing.
* @return Compatibility Manager
*/
public static @Nullable CompatibilityManager getCompatibilityManager(){
return plugin.getCompatibilityTool();
}

/**
* Gets protection plugins integration helper to allow hook your plugin to our checks system.
* If you calling this before plugin loaded up, you might get nothing.
* @return IntegrationHelper
*/
public static @Nullable IntegrationHelper getIntegrationManager(){
return plugin.getIntegrationHelper();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.abc.A.B;

import lombok.AllArgsConstructor;
import org.abc.A.N.Shop;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.abc.A.QuickShop;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@AllArgsConstructor
public class ShopAPI {
private QuickShop plugin;

/**
* Gets shop from location
* @param location The location
* @return The shop in that location, may be null
*/
public @Nullable Shop getShop(@NotNull Location location){
return plugin.getShopManager().getShop(location,false);
}
/**
* Gets shop from location with caching
* @param location The location
* @return The shop in that location, may be null
*/
public @Nullable Shop getShopWithCaching(@NotNull Location location){
if(plugin.getShopCache() == null){
return getShop(location);
}
return plugin.getShopCache().getCaching(location,false);
}

/**
* Gets shops in chunk
* @param chunk The chunk
* @return The shops in chunk, may be null
*/
public @Nullable Map<Location, Shop> getShop(@NotNull Chunk chunk){
return plugin.getShopManager().getShops(chunk);
}

/**
* Gets shop from location
* @param location The location
* @return The shop in that location, may be null
*/
public @Nullable Shop getShopIncludeAttached(@NotNull Location location){
return plugin.getShopManager().getShopIncludeAttached(location);
}
/**
* Gets shop from location and use caching
* @param location The location
* @return The shop in that location, may be null
*/
public @Nullable Shop getShopIncludeAttachedWithCaching(@NotNull Location location){
if(plugin.getShopCache() == null){
return getShopIncludeAttached(location);
}
return plugin.getShopCache().getCaching(location,true);
}

/**
* Gets a list of copy for loaded shops
* This is a expensive action, please caching the result
* @return The copy of loaded shops
*/
public @NotNull List<Shop> getLoadedShops(){
return new ArrayList<>(plugin.getShopManager().getLoadedShops());
}

/**
* Gets a list of a player's all shops
* This is a expensive action, please caching the result
* @param uuid Player UUID
* @return The list of player's all shops
*/
public @NotNull List<Shop> getPlayerAllShops(@NotNull UUID uuid){
return plugin.getShopManager().getPlayerAllShops(uuid);
}

/**
* Gets a list of all shops on this server
* This is a expensive action, please caching the result
* @return The list of all shops on server
*/
public @NotNull List<Shop> getAllShops(){
return new ArrayList<>( plugin.getShopManager().getAllShops());
}
/**
* Gets a list of all shops in world
* This is a expensive action, please caching the result
* @param world The world that you want get shops
* @return The list of all shops in world
*/
public @NotNull List<Shop> getShopsInWorld(@NotNull World world){
return plugin.getShopManager().getShopsInWorld(world);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* The QuickShop API package
* Yeah yeah i know this package name is different with other packages
* BUT! This trent, in future, all package name will be full lower-case
* For compatibility, we should do this when api creating.
*/
package org.abc.A.B;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is a part of project QuickShop, the name is BootError.java
* Copyright (C) Ghost_chu <https://github.com/Ghost-chu>
* Copyright (C) Bukkit Commons Studio and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.abc.A;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.abc.A.util.MsgUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

/**
* BootError class contains print errors on /qs command when plugin failed launched.
*/
@EqualsAndHashCode
@ToString
public class BootError {

private String[] errors;

public BootError(@NotNull String... errors) {
this.errors = errors;
for (String err : errors) {
QuickShop.instance.getLogger().severe(err);
}
}

/**
* Print the errors. ##################################################### QuickShop is disabled,
* Please fix errors and restart ..........................
* #################################################### This one.
*
* @param sender The sender you want output the errors.
*/
public void printErrors(CommandSender sender) {
MsgUtil.sendMessage(sender,ChatColor.RED + "#####################################################");
MsgUtil.sendMessage(sender,ChatColor.RED + " QuickShop is disabled, Please fix any errors and restart");
for (String issue : errors) {
MsgUtil.sendMessage(sender,ChatColor.YELLOW + " " + issue);
}
MsgUtil.sendMessage(sender,ChatColor.RED + "#####################################################");
}

public String[] getErrors() {
return errors;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* This file is a part of project QuickShop, the name is BuiltInSolution.java
* Copyright (C) Ghost_chu <https://github.com/Ghost-chu>
* Copyright (C) Bukkit Commons Studio and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.abc.A;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

/**
* A class to check known issue cause plugin failed enable.
*/
class BuiltInSolution {

/**
* Call when failed load database, and use this to check the reason.
*
* @return The reason of error.
*/
static BootError databaseError() {
return new BootError(
"Error connecting to the database",
"Make sure your database service is running.",
"Or check the configuration in your config.yml");
}

/**
* Call when failed load economy system, and use this to check the reason.
*
* @return The reason of error.
*/
static BootError econError() {
// Check Vault is installed
if (Bukkit.getPluginManager().getPlugin("Vault") == null
&& Bukkit.getPluginManager().getPlugin("Reserve") == null) {
// Vault not installed
return new BootError(
"Vault or Reserve is not installed or loaded!",
"Make sure you installed Vault or Reserve.");
}
// Vault is installed
if (Bukkit.getPluginManager().getPlugin("CMI") != null) {
// Found may in-compatiable plugin
return new BootError(
"No Economy plugin detected, did you installed and loaded them? Make sure they loaded before QuickShop.",
"Make sure you have an economy plugin hooked into Vault or Reserve.",
ChatColor.YELLOW + "Incompatibility detected: CMI Installed",
"Download CMI Edition of Vault might fix this.");
}

return new BootError(
"No Economy plugin detected, did you installed and loaded them? Make sure they loaded before QuickShop.",
"Install an economy plugin to get Vault or Reserve working.");
}

}
Loading